Notice
Recent Posts
Recent Comments
Link
«   2026/06   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Archives
Today
Total
관리 메뉴

dh-winternagi 님의 블로그

(23656) Jack and Jill 본문

백준 (C++)/Solve

(23656) Jack and Jill

dh-winternagi 2026. 4. 22. 23:24

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

단계별로 풀어보기

41단계(인터랙티브와 투 스텝 1) 3번째

 

 

 

적응하는 채점기의 적응 방식을 구현으로 알아보는 문제.

채점기와 숫자맞추기 놀이를 하는데 채점기가 맞추는 쪽이다.

이분 탐색의 개념에서 착안하여 채점기가 최대한 오래 맞추지 못하도록 정답 범위가 덜 좁아지는 방향으로 답변하면 된다.

절대 아닌 답을 다시 물어본다던가 하는 괴상한 짓도 하니 그런 것도 예외처리해줘야 한다.

 

 

 

#include <iostream>
using namespace std;

int main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  
  long resp, l=1, r=1000000000;
  
  while(true){
    cin >> resp;
    
    if(resp<l){
      cout << ">" << endl;
    }else if(r<resp){
      cout << "<" << endl;
    }else if(l==r){
      cout << "=" << endl;
      break;
    }else if(r-resp>resp-l){
      cout << ">" << endl;
      l= resp+1;
    }else{
      cout << "<" << endl;
      r= resp-1;
    }
  }
  
  return 0;
}

'백준 (C++) > Solve' 카테고리의 다른 글

(19554) Guess the number  (0) 2026.04.22
(31430) A+B - 투 스텝  (0) 2026.04.22
(30924) A+B - 10 (제2편)  (0) 2026.04.22
(30917) A+B - 10 (제1편)  (0) 2026.04.22
(25953) 템포럴 그래프  (0) 2026.04.22