Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

16-pu2rile #51

Merged
merged 1 commit into from
Sep 24, 2024
Merged

16-pu2rile #51

merged 1 commit into from
Sep 24, 2024

Conversation

pu2rile
Copy link
Collaborator

@pu2rile pu2rile commented Sep 14, 2024

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

๋ฐฑ์ค€ - ์‹ ์ž… ์‚ฌ์›

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

40๋ถ„

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

์•„์ด๋””์–ด

์„œ๋ฅ˜ ์„ฑ์  ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌ ํ›„ ๋ฉด์ ‘ ์„ฑ์ ๋งŒ ๋น„๊ต

ํ’€์ด ๋ฐฉ๋ฒ•

  1. ์„œ๋ฅ˜ ์„ฑ์  ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌ
    • ์„œ๋ฅ˜ ์„ฑ์ ์„ ๊ธฐ์ค€์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ
      -> ์„œ๋ฅ˜ ์„ฑ์ ์ด ๋” ๋‚ฎ์€ ์ง€์›์ž๋Š” ์ž๋™์œผ๋กœ ๊ฑฐ๋ฅผ ์ˆ˜ ์žˆ๊ฒŒ ๋จ
  2. ์ฒซ ๋ฒˆ์งธ ์ง€์›์ž ํ•ฉ๊ฒฉ ์ฒ˜๋ฆฌ
    • ์ฒซ ๋ฒˆ์งธ ์ง€์›์ž๊ฐ€ ๊ฐ€์žฅ ์„œ๋ฅ˜ ์„ฑ์ ์ด ์ข‹๊ธฐ ๋•Œ๋ฌธ์— ํ•ฉ๊ฒฉ์œผ๋กœ ์ฒ˜๋ฆฌ
    • ๋‘ ๋ฒˆ์งธ ์ง€์›์ž๋ถ€ํ„ฐ ๋ฉด์ ‘ ์„ฑ์  ๋น„๊ต
    top = 0 # ์„œ๋ฅ˜ ์„ฑ์ ์ด ๊ฐ€์žฅ ์ข‹์€ ์‚ฌ๋žŒ์„ ๊ธฐ์ค€์œผ๋กœ ์„ค์ • (์ฒซ ๋ฒˆ์งธ ์‚ฌ๋žŒ)
    result = 1  # ์ฒซ ๋ฒˆ์งธ ์ง€์›์ž๋Š” ํ•ญ์ƒ ํ•ฉ๊ฒฉํ•˜๋ฏ€๋กœ ๊ฒฐ๊ณผ๋ฅผ 1๋กœ ์‹œ์ž‘
    # 2๋ฒˆ์งธ ์ง€์›์ž๋ถ€ํ„ฐ ์„œ๋ฅ˜ ์„ฑ์  ์ˆœ์œผ๋กœ ๋ฉด์ ‘ ์„ฑ์  ๋น„๊ต
    for i in range(1, len(rank_1)):
  3. ๋ฉด์ ‘ ์„ฑ์  ๋น„๊ต(๊ทธ๋ฆฌ๋”” ๋ฐฉ์‹)
    • ์„œ๋ฅ˜ ์„ฑ์ ์ด ๋†’์€ ์ง€์›์ž๋“ค์˜ ๋ฉด์ ‘ ์„ฑ์ ์„ ์ฐจ๋ก€๋กœ ๋น„๊ต
    • ํ˜„์žฌ ํ™•์ธํ•˜๋Š” ์ง€์›์ž๊ฐ€ ๊ธฐ์ค€์ (top)๋ณด๋‹ค ๋ฉด์ ‘ ์„ฑ์ ์ด ์ข‹๋‹ค๋ฉด ๊ทธ ์ง€์›์ž๋Š” ์„ ๋ฐœ
    • ๋ฉด์ ‘ ์„ฑ์ ์ด ์ข‹์€ ์ง€์›์ž๊ฐ€ ๋‚˜์˜ค๋ฉด ๊ทธ ์ง€์›์ž๋ฅผ ์ƒˆ๋กœ์šด ๊ธฐ์ค€์ ์œผ๋กœ ๊ฐฑ์‹ ํ•˜๊ณ  ์ดํ›„์˜ ์ง€์›์ž๋“ค๊ณผ ๋น„๊ต
    if rank_1[i][1] < rank_1[top][1]:
            top = i # ๊ธฐ์ค€์ (top)์„ ํ˜„์žฌ ์ง€์›์ž๋กœ ๊ฐฑ์‹ 
            result += 1

์ „์ฒด ์ฝ”๋“œ

(์ˆ˜์ • ์ „)

T = int(input())

for _ in range(T):
    N = int(input())
    score = [list(map(int, input().split())) for _ in range(N)]

    # ์„œ๋ฅ˜ ์‹ฌ์‚ฌ ์„ฑ์  ๊ธฐ์ค€์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ
    rank_1 = sorted(score)
    top = 0 # ์„œ๋ฅ˜ ์„ฑ์ ์ด ๊ฐ€์žฅ ์ข‹์€ ์‚ฌ๋žŒ์„ ๊ธฐ์ค€์œผ๋กœ ์„ค์ • (์ฒซ ๋ฒˆ์งธ ์‚ฌ๋žŒ)
    result = 1  # ์ฒซ ๋ฒˆ์งธ ์ง€์›์ž๋Š” ํ•ญ์ƒ ํ•ฉ๊ฒฉํ•˜๋ฏ€๋กœ ๊ฒฐ๊ณผ๋ฅผ 1๋กœ ์‹œ์ž‘
    
    # 2๋ฒˆ์งธ ์ง€์›์ž๋ถ€ํ„ฐ ์„œ๋ฅ˜ ์„ฑ์  ์ˆœ์œผ๋กœ ๋ฉด์ ‘ ์„ฑ์  ๋น„๊ต
    for i in range(1, len(rank_1)):
        # ํ˜„์žฌ ์ง€์›์ž์˜ ๋ฉด์ ‘ ์„ฑ์ ์ด ๊ธฐ์ค€์ (top)์˜ ์ง€์›์ž๋ณด๋‹ค ์ข‹์œผ๋ฉด (์ˆซ์ž๊ฐ€ ๋‚ฎ์œผ๋ฉด)
        if rank_1[i][1] < rank_1[top][1]:
            top = i # ๊ธฐ์ค€์ (top)์„ ํ˜„์žฌ ์ง€์›์ž๋กœ ๊ฐฑ์‹ 
            result += 1
    
    print(result)   

(์ˆ˜์ • ํ›„)

import sys

T = int(sys.stdin.readline())  # ๋ณ€๊ฒฝ ์‚ฌํ•ญ

for _ in range(T):
    N = int(sys.stdin.readline())  # ๋ณ€๊ฒฝ ์‚ฌํ•ญ
    score = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]  # ๋ณ€๊ฒฝ ์‚ฌํ•ญ
    rank_1 = sorted(score)
    top = 0
    result = 1
    
    for i in range(1, N):  # ๋ณ€๊ฒฝ ์‚ฌํ•ญ
        if rank_1[i][1] < rank_1[top][1]:
            top = i
            result += 1
    
    print(result)

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

์‹œ๊ฐ„ ์ดˆ๊ณผ ๋– ์„œ ์ผ๋ถ€ ์ฝ”๋“œ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค!!!!!!!!

๋งˆ๊ฐ์ผ์„ ์ฐฉ๊ฐํ•ด์„œ pr์„ ๋Šฆ๊ฒŒ ์˜ฌ๋ ค ๋ฒ„๋ ธ์Šต๋‹ˆ๋‹ค... ์ฃ„์†กํ•ด์š” ใ… ใ…  ๋‹ค์Œ ์ฃผ๋ถ€ํ„ฐ๋Š” ์ œ๋•Œ ์ž˜ ์˜ฌ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค!!
์ฆ๊ฑฐ์šด ๋ช…์ ˆ ๋˜์„ธ์š” ๐ŸŒ๐Ÿ’ต

Copy link
Member

@oesnuj oesnuj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์„œ๋ฅ˜ ์„ฑ์  ์ˆœ์œผ๋กœ ์ •๋ ฌํ•œ ๋’ค, ์ด์ „์— ์„ ํƒ๋œ ์ง€์›์ž๋ณด๋‹ค ๋ฉด์ ‘ ์„ฑ์ ์ด ๋” ์šฐ์ˆ˜ํ•œ ๊ฒฝ์šฐ์—๋งŒ ํ•ด๋‹น ์ง€์›์ž๋ฅผ ๋ฝ‘๋Š” ๋ฐฉ์‹์ด๋„ค์š”.
๊ทธ๋ฆฌ๋”” ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด์ง€๋งŒ, ์ƒ๊ฐ๋ณด๋‹ค ์ด ๋ฐฉ์‹์ด ๋ฐ”๋กœ ๋– ์˜ค๋ฅด์ง€ ์•Š์•˜๋˜ ๊ฒƒ ๊ฐ™์•„์š”. ๊ทธ๋ฆฌ๋”” ๋ฌธ์ œ๋„ ์—ฌ๋Ÿฌ ๋ฒˆ ์—ฐ์Šตํ•ด๋ด์•ผ ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!

์ €๋Š” ์ด๋ ‡๊ฒŒ ํ’€์–ด๋ดค์Šต๋‹ˆ๋‹ค. ๋„ํ˜„๋‹˜ ํ’€์ด์™€ ๊ฑฐ์˜ ๋น„์Šทํ•œ ๊ฒƒ ๊ฐ™๋„ค์š”

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct Applicant {
    int docRank;
    int intvRank;

    bool operator<(const Applicant& other) const {
        return docRank < other.docRank;
    }
};

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int T;
    cin >> T;
    while (T--) {
        int n;
        cin >> n;
        vector<Applicant> v(n);
        for (auto& i : v) {
            cin >> i.docRank >> i.intvRank;
        }

        sort(v.begin(), v.end());

        int top = v[0].intvRank;
        int cnt = 1;
        for (int i = 1; i < n; i++) {
            if (v[i].intvRank < top) {
                top = v[i].intvRank;
                cnt++;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

PR ์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค! ๋„ํ˜„๋‹˜๋„ ์ฆ๊ฑฐ์šด ์—ฐํœด ๋ณด๋‚ด์„ธ์š”๐Ÿ˜„

Copy link
Collaborator

@suhyun113 suhyun113 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋‹ค๋ฅธ ๋ชจ๋“  ์ง€์›์ž์™€ ๋น„๊ตํ•˜์—ฌ ์„œ๋ฅ˜ ์‹ฌ์‚ฌ์„ฑ์ ๊ณผ ๋ฉด์ ‘์‹œํ—˜ ์„ฑ์  ์ค‘ ์ ์–ด๋„ ํ•˜๋‚˜๊ฐ€ ๋‹ค๋ฅธ ์ง€์›์ž๋ณด๋‹ค ๋–จ์–ด์ง€์ง€ ์•Š๋Š” ์ž๋งŒ ์„ ๋ฐœํ•œ๋‹ค??? ์ดํ•ด๊ฐ€ ๋˜๋ฉด์„œ ์•„๋ฆฌ๊นŒ๋ฆฌํ•œ,,, ๊ทธ๋ ‡๋„ค์š”... ๋ฌธ์ œ ์ดํ•ด๊ฐ€ ์–ด๋ ค์› ๋„ค์š”ใ… ใ… 

๋„ํ˜„๋‹˜๊ป˜์„œ๋Š” ์„œ๋ฅ˜ ์‹ฌ์‚ฌ์„ฑ์ ์„ ๊ธฐ์ค€์œผ๋กœ ํ•˜์—ฌ ๋ฉด์ ‘์‹œํ—˜ ์„ฑ์ ๋งŒ ๋น„๊ตํ•˜๋Š” ๊ทธ๋ฆฌ๋”” ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•œ ๊ฒƒ ๊ฐ™์€๋ฐ ํšจ์œจ์ ์œผ๋กœ ์ž˜ ํ•˜์‹  ๊ฒƒ ๊ฐ™์•„์š”!
sys.stdin.readline() ์ €๋„ ์‚ฌ์šฉํ•ด๋ณธ ๊ฒƒ ๊ฐ™์€๋ฐ, ์‹œ๊ฐ„ ์ดˆ๊ณผ๋ฅผ ํ•ด๊ฒฐํ•˜๋Š” ์ข‹์€ ๋ฐฉ๋ฒ•์ด๋ผ๋”๊ตฐ์š”,, ํŒŒ์ด์ฌ์„ ์ด์šฉํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ’€๋‹ค๋ณด๋‹ˆ ๊ฑฐ์˜ ํ•ญ์ƒ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ ๊ฐ™์•„์š”~

16PR ์ˆ˜๊ณ ํ•˜์…จ์–ด์š”!!๐Ÿ˜„

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants