GDUT_寒假训练题解报告_专题I_H题 个人题解报告

GDUT_寒假训练题解报告_专题I_H题 个人题解报告

题目:

Obs: this is an interactive problem. More information is under the “Interaction” section.

MaratonIME is gathering to start another group practice. This time, Renzo decided to reward the students with candies as they solve problems. Curious as they are, the members of MaratonIME started to guess how many candies did Renzo bring. For each question, Renzo answered if the amount of candies was higher, lower or equal to the number asked.

Breno, noticing that the amount of candies could be very high, decided to limit the number of queries to 50. This way, the practice would start as soon as possible.

Renzo bought at least 1 and no more than 109 candies. Find how many candies were bought by Renzo with no more than 50 questions.

Input

For every question asked, read a character. It will be " > " if the amount of Renzo’s candies is higher than your guess, " < " if the amount of Renzo’s candies is lower than your guess or " = " if your guess is equal to the amount of Renzo’s candies.

Output

You must print every query in the format “Q y”, where y is the number guessed, and 1 ≤ y ≤ 109. After printing a question, you need to flush the output. Check the “Interaction” section for examples of how to flush the output.

Interaction

To ask Renzo a question, print the query in the format above. After printing a question, you need to flush the output. See examples below for each language:

C: fflush(stdout)

C++: cout.flush()

Java: System.out.flush()

Python: sys.stdout.flush()

Pascal: flush(output)

After each query, read a character as described above.

As soon as Renzo answers your question with “=” the program has to terminate. Your answer will be considered correct if you asked no more than 50 questions.

Example

Input
:>
:<
:=

Output

Q 1
Q 3
Q 2
Note
In the example, the number of candies is 2. The answer is considered to be correct because only 3 out of the 50 possible questions were asked to obtain the character " = ".

Make sure to flush the output after printing each question!

这是一个交互题目,当然还是二分,要求是找一个小于1e9的数,在50次询问下找一个2^30级别的数,那就用二分把,代码很水

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <climits>

using namespace std;
int main()
{
	int left=1;
	int right=1e9;
	char ch;
	while(right>left)
	{
		printf("Q %d\n",left+(right-left)/2);
		cin>>ch;
		if(ch=='=')break;
		if(ch=='>')left=left+(right-left)/2+1;
		else right=left+(right-left)/2;

	}
	printf("Q %d\n",left);
	cin>>ch;
	return 0;

}

我是没搞懂他的刷新输出是啥,但是我printf能过,可能是cout的问题?

发布了8 篇原创文章 · 获赞 0 · 访问量 114

猜你喜欢

转载自blog.csdn.net/DevourPower/article/details/103963413