[BOJ/11968] High Card Wins, c++

2021. 12. 22. 20:02ยทDEV/PS

๐Ÿ”— ๋งํฌ

https://www.acmicpc.net/problem/11968

 

11968๋ฒˆ: High Card Wins

Bessie the cow is a huge fan of card games, which is quite surprising, given her lack of opposable thumbs. Unfortunately, none of the other cows in the herd are good opponents. They are so bad, in fact, that they always play in a completely predictable fas

www.acmicpc.net

๐Ÿคฏ ํ•œ์ค„ ํ›„๊ธฐ

๋ˆ„๊ฐ€ ์นด๋“œ ์ˆœ์„œ๋ฅผ ๋ฏธ๋ฆฌ ์•Œ๊ณ  .. ๋ถˆ๋ฒ• ์•„๋‹˜ ?

๐Ÿคท ๋ฌธ์ œ

๐Ÿ‘ฉ‍๐Ÿ’ป ํ’€์ด

์—„์ฒญ ์˜ˆ์ „์— ํ‹€๋ ธ๋‹ค๊ฐ€ ์˜ค๋Š˜ ๊ฐœ๋ฐœํ•˜๊ธฐ ์‹ซ์–ด์„œ ๋‹ค์‹œ ํ’€์–ด๋ณด์•˜๋‹ค.

๋ฌธ์ œ๊ฐ€ ์˜์–ด์ง€๋งŒ ๊ฐ„๋‹จํžˆ ํ•ด์„ํ•ด๋ณด๋ฉด

elsie ์™€ bessie ๊ฐ€ 1~2*round ๊ฐ€ ์ ํžŒ ์นด๋“œ๋ฅผ ๊ฐ€์ง€๊ณ  ๋‘˜์ด ๋ฐ˜์”ฉ ๋‚˜๋ˆ ์„œ ์นด๋“œ๊ฒŒ์ž„์„ ์ง„ํ–‰ํ•œ๋‹ค.

์ฃผ์–ด์ง„ round ๋งˆ๋‹ค ๋” ํฐ ๊ฐ’์ด ์ ํžŒ ์นด๋“œ๋ฅผ ๋‚ด๋Š” ์‚ฌ๋žŒ์ด Point๋ฅผ ์–ป๊ฒŒ ๋œ๋‹ค. ์ด๋•Œ elsie๋Š” bessie์˜ ์นด๋“œ ์ˆœ์„œ๋ฅผ ์•Œ๊ณ  ์žˆ๋‹ค.

elsie๊ฐ€ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ์ ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•˜๋ฉด ๋˜๋Š” ๋ฌธ์ œ์ด๋‹ค.

์ด๊ฑธ ๋จธ๋ฆฟ์†์œผ๋กœ ์ƒ๊ฐํ•˜๋ฉด ์ง„์งœ ๋„ˆ๋ฌด ๋น ๋ฅด๊ฒŒ ๋œ๋‹ค. ๊ทธ๋ƒฅ bessie๊ฐ€ ๊ฐ€์ง€์ง€ ๋ชปํ•œ ์นด๋“œ์ค‘ bessie๊ฐ€ ๊ฐ€์ง„ ์นด๋“œ๋ณด๋‹ค ๊ฐ’์ด ๋” ํฐ ๊ฐœ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•˜๋ฉด ๋œ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ ใ„ฑ- ๋„ˆ๋ฌด ์˜ค๋žœ๋งŒ์— (์•ฝ ๋‘๋‹ฌ) PS ๋ฌธ์ œ๋ฅผ ํ‘ธ๋‹ˆ๊นŒ ์ง„์‹ฌ ๋จธ๋ฆฌ๊ฐ€ ๋Œ์ด ๋œ ๊ฒƒ ๊ฐ™์Œ!!!!

๋ฌดํŠผ ๋‚˜๋Š” ์ข€ ๊ฑฐ์˜ brute force ๋А๋‚Œ์œผ๋กœ ํ’€์–ด์„œ 8ms๊ฐ€ ๊ฑธ๋ ธ๋Š”๋ฐ ๋‚˜์ค‘์— 4ms์˜ ํ’€์ด๋ฅผ ๋ณด๋‹ˆ๊นŒ ํ›จ์”ฌ ํšจ์œจ์ ์ด๊ณ  ๊น”๋”ํ•˜๊ฒŒ ํ’€์—ˆ๋”๋ผ...

๋‚˜๋Š” bessie์˜ ์นด๋“œ๋ฅผ ๋ชจ๋‘ vector์— ๋„ฃ์–ด ๋†“๊ณ , sorting ํ•ด์คฌ๋‹ค. ์ดํ›„์— bessie๊ฐ€ ๊ฐ€์ง€์ง€ ๋ชปํ•œ ์นด๋“œ๋ฅผ elsie vector์— ๋„ฃ์–ด ๋†“๊ณ  ๋˜‘๊ฐ™์ด sorting ํ•ด์คฌ๋‹ค. ์ด์ œ elsie์˜ ์นด๋“œ๋ฅผ ๋Œ๋ฉด์„œ bessie ๋ณด๋‹ค ํฐ ์นด๋“œ๋ฅผ ๊ฐ€์กŒ์œผ๋ฉด point๋ฅผ ๋Š˜๋ ค์ฃผ์—ˆ๋‹ค. 

์ค‘๊ฐ„์— bessie์˜ card index๊ฐ€ round ๋ฅผ ๋„˜์–ด๊ฐ€๋ฉด ๋ฐ”๋กœ ๋๋‚ด ์ฃผ์—ˆ๋‹ค. (out of bounds ์˜ˆ์™ธ์ฒ˜๋ฆฌ)

๐Ÿ’ป ์ฝ”๋“œ

//AC
//BOJ 11968 High Card Wins
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> card;
vector<int> elsie;
int visit[101010];
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int round, num;
    cin >> round;
    for(int i=0; i<round; i++) {
        cin >> num;
        card.push_back(num);
        visit[num] = 1;
    }
    sort(card.begin(), card.end()); // bessie ์นด๋“œ sorting
    for(int i=1; i<=round*2; i++) {
        if(!visit[i]){
            elsie.push_back(i);  // bessie๊ฐ€ ๊ฐ€์ง€์ง€ ๋ชปํ•œ ์นด๋“œ๋ฅผ elsie ์—๊ฒŒ ๋„ฃ์–ด์ค€๋‹ค.
        }
    }
    sort(elsie.begin(), elsie.end());  // elsie ์นด๋“œ sorting
    int index = 0, point = 0;
    for(int elsie_card : elsie) {
        if (index >= round)  break;  // index ์˜ˆ์™ธ์ฒ˜๋ฆฌ
        if (elsie_card > card[index]) {
            index++;
            point++;  // elsie ์นด๋“œ๊ฐ€ bessie ์นด๋“œ๋ณด๋‹ค ํฌ๋‹ค๋ฉด bessie index๋ฅผ ๋Š˜๋ ค์ฃผ๊ณ  elsie์˜ point๋ฅผ 1์  ๋Š˜๋ ค์ค€๋‹ค.
        }
           
    } 
    cout << point;
    return 0;
}
์ €์ž‘์žํ‘œ์‹œ ๋น„์˜๋ฆฌ ๋ณ€๊ฒฝ๊ธˆ์ง€ (์ƒˆ์ฐฝ์—ด๋ฆผ)

'DEV > PS' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[BOJ/20208] ์ง„์šฐ์˜ ๋ฏผํŠธ์ดˆ์ฝ” ์šฐ์œ , c++  (0) 2021.09.20
[BOJ/14746] Closest Pair, c++  (0) 2021.09.20
[BOJ/20218] Parity Constraint Shortest Path, c++  (1) 2021.08.28
[BOJ/20666] ์ธ๋ฌผ์ด์™€ ์ •์ˆ˜, c++  (2) 2021.08.20
[BOJ/20665] ๋…์„œ์‹ค ๊ฑฐ๋ฆฌ๋‘๊ธฐ, c++  (2) 2021.08.20
'DEV/PS' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€
  • [BOJ/20208] ์ง„์šฐ์˜ ๋ฏผํŠธ์ดˆ์ฝ” ์šฐ์œ , c++
  • [BOJ/14746] Closest Pair, c++
  • [BOJ/20218] Parity Constraint Shortest Path, c++
  • [BOJ/20666] ์ธ๋ฌผ์ด์™€ ์ •์ˆ˜, c++
jobchae
jobchae
๋งํ•˜๋Š” ๊ฐ์ž์ง€๋งŒ, ์ฝ”๋“œ๋ฅผ ๋„์ ์ด๋Š” Node.js ๋ฐฑ์—”๋“œ ๊ฐœ๋ฐœ์ž์ž…๋‹ˆ๋‹ค.
  • jobchae
    JOBCHAE
    jobchae
  • ์ „์ฒด
    ์˜ค๋Š˜
    ์–ด์ œ
    • ๐Ÿš€ JOBCHAE (177)
      • DEV (146)
        • PS (108)
        • Node.js (12)
        • React (3)
        • docker (1)
        • ์žก๋‹คํ•œ ๊ฐœ๋ฐœ ์ผ์ง€ (20)
        • injection (1)
        • CI CD (0)
        • JS, TS (1)
      • ์ถ•๊ตฌ (0)
      • ์ผ์ƒ (19)
      • ์˜ํ™” (3)
      • ์Œ์•… (8)
  • ๋ธ”๋กœ๊ทธ ๋ฉ”๋‰ด

    • ๐Ÿ’ป Github
    • ๐Ÿ™‹๐Ÿป Linkedin
    • ๐Ÿ“– ๋ฐฉ๋ช…๋ก
  • ๋งํฌ

    • PS Github
  • ๊ณต์ง€์‚ฌํ•ญ

  • ์ธ๊ธฐ ๊ธ€

  • ํƒœ๊ทธ

    boj
    Express
    ์Šฌ๋ž™๋ด‡
    Nest.js
    react
    ๋ฐฑ์ค€
    ์•ฑ์žผ
    ํšŒ๊ณ 
    mongoDB
    DFS
    node.js
    ๋ ›์ธ ๋ฝํŽ˜์Šคํ‹ฐ๋ฒŒ
    ๋ฆฌ์•กํŠธ
    GitHub
    ์•Œ๊ณ ๋ฆฌ์ฆ˜
    PS
    DP
    slack
    ์ด๋ถ„ํƒ์ƒ‰
    SOPT
    ์†ํŠธ
    ์Šฌ๋ž™
    aws
    Nest
    ์ผ์ƒ
    typescript
    BFS
    ์œ„์ƒ์ •๋ ฌ
    ์šฐ์„ ์ˆœ์œ„ํ
    nodejs
  • ์ตœ๊ทผ ๋Œ“๊ธ€

  • ์ตœ๊ทผ ๊ธ€

  • hELLOยท Designed By์ •์ƒ์šฐ.v4.10.0
jobchae
[BOJ/11968] High Card Wins, c++
์ƒ๋‹จ์œผ๋กœ

ํ‹ฐ์Šคํ† ๋ฆฌํˆด๋ฐ”