Skip to content

Conversation

@froglike6
Copy link
Collaborator

@froglike6 froglike6 commented May 8, 2025

πŸ”— 문제 링크

κ²Œμž„

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

20λΆ„

✨ μˆ˜λ„ μ½”λ“œ

μˆ˜λ„ μ½”λ“œ

1. Z = (Y * 100) // X  # κΈ°μ‘΄ 승λ₯  계산
2. λ§Œμ•½ Z >= 99이면, -1을 좜λ ₯ν•˜κ³  μ’…λ£Œ

3. left = 1
4. right = 1000000000
5. answer = -1

6. while left <= right:
    a. mid = (left + right) // 2
    b. new_Z = ((Y + mid) * 100) // (X + mid)
    
    c. λ§Œμ•½ new_Z > Z:
        i. answer = mid
        ii. right = mid - 1  # 더 적은 κ²Œμž„ 수둜 κ°€λŠ₯ν• μ§€ 탐색
    d. μ•„λ‹ˆλ©΄, left = mid + 1

7. 좜λ ₯ answer

이 λ¬Έμ œλŠ” μ£Όμ–΄μ§„ κ²Œμž„ 횟수 X와 이긴 κ²Œμž„μ˜ 횟수 Yκ°€ μ£Όμ–΄μ‘Œμ„ λ•Œ, 승λ₯ μ˜ μ •μˆ˜ 뢀뢄이 λ°”λ€ŒκΈ° μœ„ν•΄μ„œ λͺ‡ νŒμ„ 더 이겨야 ν•˜λŠ”μ§€ κ΅¬ν•˜λŠ” λ¬Έμ œμž…λ‹ˆλ‹€.
X=53이고, Y=47이면 (47/53)*100=88....μ΄λ―€λ‘œ Z=88이 λ©λ‹ˆλ‹€. μ—¬κΈ°μ„œ Zκ°€ λ°”λ€ŒκΈ° μœ„ν•œ 수λ₯Ό 직접 μ°ΎλŠ” 것은 였래 κ±Έλ¦¬λ―€λ‘œ, 이뢄 탐색을 μ‚¬μš©ν–ˆμŠ΅λ‹ˆλ‹€. μƒˆλ‘œμš΄ 승λ₯  Z`=((Y + mid) * 100) // (X + mid)이 λ°”λ€ŒλŠ” μ΅œμ†Œ midλ₯Ό μ°ΎλŠ” 이뢄 탐색을 톡해 문제λ₯Ό ν•΄κ²°ν–ˆμŠ΅λ‹ˆλ‹€.

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

@froglike6 froglike6 self-assigned this May 8, 2025
@froglike6 froglike6 marked this pull request as ready for review May 8, 2025 05:12
@froglike6 froglike6 changed the base branch from 9-froglike6 to main May 8, 2025 06:03
Copy link
Collaborator

@hadongun hadongun left a comment

Choose a reason for hiding this comment

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

처음 보고 κ·Έλƒ₯ for문으둜 ν’€λ € ν–ˆλŠ”λ°.. X λ²”μœ„λ₯Ό λ³΄λ‹ˆ μ‹œκ°„ μ΄ˆκ³Όκ°€ λ‚  게 λ»”ν•œ 것 κ°™λ”κ΅°μš”..!

이뢄 νƒμƒ‰μœΌλ‘œ ν’€μ–΄ λ΄€λŠ”λ°, 아직 μ΅μˆ™ν•˜μ§€ μ•Šμ•„μ„œ μ‹œκ°„μ΄ μ’€ κ±Έλ¦¬λ„€μš©
파이썬으둜 ν’€μ–΄λ΄€μ–΄μš₯

νŒŒμ΄ν—Œ

import sys

left = 1
right = 1000000000
x, y = map(int, input().split())
Z = (y*100)//x
answer = -1
def condition(mid):
    return ((y + mid) * 100) // (x + mid) > Z

if Z >= 99:
    print(-1)
    sys.exit()
while left <= right:
    mid = (left + right)//2

    if condition(mid):
        answer = mid
        right = mid -1
    else:
        left = mid + 1

print(answer)

Copy link
Contributor

@dohyeondol1 dohyeondol1 left a comment

Choose a reason for hiding this comment

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

보고 μ΄λΆ„νƒμƒ‰μœΌλ‘œ ν’€μ–΄μ•Όκ² λ‹€λŠ” 생각은 λ“€μ—ˆλŠ”λ°...
λ²”μœ„λ₯Ό μ–΄λ–»κ²Œ μž‘μ•„μ•Ό ν•˜λŠ”μ§€μ— λŒ€ν•΄μ„œ ν•œμ°Έ κ³ λ―Ό ν–ˆμŠ΅λ‹ˆλ‹€.
도무지 λͺ¨λ₯΄κ² μ–΄μ„œ κ·Έλƒ₯ μ΅œλŒ“κ°’μœΌλ‘œ 작고 ν’€μ—ˆλ”λ‹ˆ λ§žμ•˜λ„€μš”.. γ…Ž

μ €λŠ” 라이브러리 ν•¨μˆ˜λ₯Ό μ‚¬μš©ν•˜λŠ”κ²Œ μ•„λ‹ˆλΌλ©΄ μ»€μŠ€ν…€ ν•¨μˆ˜λ‘œ λ§Œλ“€μ–΄ μ“°λŠ” 편인데,
λ„ν˜„λ‹˜ μ½”λ“œλ₯Ό λ³΄λ‹ˆ ꡳ이 ν•¨μˆ˜λ‘œ κ΅¬ν˜„ν•˜μ§€ μ•Šμ•˜λ”λΌλ„ ν’€ 수 μžˆμ—ˆμ„ κ±°λΌλŠ” 생각이 λ“œλ„€μš”.

C++
#include <iostream>
using namespace std;

long long binary_search(long long gameCount, long long winCount) {
    long long currentRate = 100*winCount/gameCount;
    long long result = -1;
    
    long long left = 0, right = 1e9;
    while(left <= right) {
        long long mid = (left+right)/2;
        long long newWinRate = 100*(winCount+mid)/(gameCount+mid);
        
        if(newWinRate > currentRate) {
            result = mid;
            right = mid-1;
        }
        else left = mid+1;
    }
    
    return result;
}

int main() {
    long long X, Y, Z;
    cin >> X >> Y;
    Z = 100*Y/X;
    
    if(Z >= 99) {
        cout << -1 << '\n';
        return 0;
    }
    
    long long minCount = binary_search(X, Y);
    cout << minCount << '\n';
    
    return 0;
}

Copy link
Collaborator

@caucsejunseo caucsejunseo left a comment

Choose a reason for hiding this comment

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

이뢄탐색이 아직 μ–΄μƒ‰ν•΄μ„œ λ°”λ‘œλ°”λ‘œ λ– μ˜€λ₯΄μ§„ μ•Šλ„€μš”. μ†Œμˆ˜ 계산을 μ˜€λžœλ§Œμ— ν•΄λ΄μ„œ Z = (Y / X)*100; 이런 μ‹μœΌλ‘œ ν•˜λ‹€κ°€ 였래 ν—€λ§Έλ„€μš”

씨

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>



int main() {
    long long X, Y;
    scanf("%lld %lld", &X, &Y);

    long long Z = (Y * 100) / X;

    if (Z >= 99) {
        printf("-1\n");
        return 0;
    }

    long long left = 1;
    long long right = 1000000000;
    long long result = -1;

    while (left <= right) {
        long long mid = (left + right) / 2;
        long long newZ = ((Y + mid) * 100) / (X + mid);

        if (newZ > Z) {
            result = mid;
            right = mid - 1;
        }
        else {
            left = mid + 1;
        }
    }

    printf("%lld\n", result);
    return 0;
}

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.

5 participants