您的位置:首页 > 运维架构

ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 C. Colder-Hotter

2015-12-23 15:39 417 查看
C. Colder-Hotter

time limit per test
1 second

memory limit per test
512 megabytes

input
standard input

output
standard output

This is an interactive problem.

Egor and Petr are playing a game called «Colder-Hotter» on a 2D plane. At the beginning of the game Egor thinks of a point with non-negative integer coordinates not exceeding 109. Then Petr tries to guess this point: on the i-th turn he chooses some point with integer coordinates (xi, yi) and tells them to Egor. If this point is closer to the one being guessed than the previous point (xi - 1, yi - 1), then Egor answers "1". Otherwise, and also if this is the first turn of the game, he answers "0".

When there are no more turns left or Petr thinks he has enough information, he stops the game and tells his answer. If the answer is correct Petr is considered to be a winner. As Petr becomes more and more experienced, Egor reduces the number of turns.

The current limit on the number of turns in their game is 500. Petr asks you to write a program that will successfully beat Egor.

Egor is a fair player and does not change the point after the game has started.

Input
The jury program outputs either "1" in case when the current point from player is closer to the one being guessed than the previous point, or "0" when the current point from player is not closer than previous one or there is no previous point.

Output
If a player makes a turn, he must output two integer numbers with a single space character between them — x- and y-coordinates of the pronounced point (0 ≤ x, y ≤ 109). If a player wants to stop the game he must output a character 'A' and then two integer numbers — x- and y-coordinates of the guessed point, and then stop the program.

After each output (one guess or answer) you must print one end of line, flush output stream, and read the answer. See the notes if you do not know how to execute a flush command. If your program receives an EOF (end-of-file) condition on the standard input, it must exit immediately with exit code 0. Failure to comply with this requirement may result in "Time Limit Exceeded" error.

It is guaranteed that the coordinates of the point being guessed are non-negative and do not exceed 109.

Sample test(s)

input
0

0

1

0

1

0


output
1 1

0 0

20 20

20 20

17 239

17 240

A 17 239


Note
The point being guessed in the sample is (x = 17, y = 239). One of the possible scenarios of the game is shown:

Petr names the point (1, 1) and Egor replies 0, because it is the first turn.

Petr now names the point (0, 0) which is farther from (x = 17, y = 239) than (1, 0), thus Egor replies 0 again.

Next point is (20, 20), and now the reply is 1.

Now Petr names (20, 20) again just to show you that the answer for this case is 0, because the relation "closer" is irreflexive.

Now Petr accidentally names the point (17, 239), but Egor doesn't say that this is the answer: according to the game rules he just says that it's closer to the point being guessed than the previous one.

Egor answers 0 for (17, 240).

Petr decides to try his fortune and names the point (17, 239). Note that he actually hasn't had enough information to be sure, so he is correct accidentally.

To flush the standard output stream, use the following statements:

In C, use fflush(stdout);

In C++, use cout.flush();

In Java, use System.out.flush();

题意:交互题。

有一个坐标 X,Y,你可以进行询问,每一次询问,他都会返回0/1,如果你的点比上一个点接近生成坐标,则会返回1,否则0

分析:显然是先确定x坐标,在确定y的坐标。

联想到距离公式,三分即可

/**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair

inline int Getint()
{
int Ret = 0;
char Ch = ' ';
bool Flag = 0;
while(!(Ch >= '0' && Ch <= '9'))
{
if(Ch == '-') Flag ^= 1;
Ch = getchar();
}
while(Ch >= '0' && Ch <= '9')
{
Ret = Ret * 10 + Ch - '0';
Ch = getchar();
}
return Flag ? -Ret : Ret;
}

int ans[2];

bool Check(int x, int y, int w)
{
static int tmp[2];
int ret;
tmp[w] = x, tmp[w ^ 1] = ans[w ^ 1];
//printf("%d %d\n", tmp[0], tmp[1]);
cout << tmp[0] << ' ' << tmp[1] << endl;
//scanf("%d", &ret);
cin >> ret;
tmp[w] = y;
//printf("%d %d\n", tmp[0], tmp[1]);
cout << tmp[0] << ' ' << tmp[1] << endl;
//scanf("%d", &ret);
cin >> ret;
return ret;
}

inline void Work(int w)
{
int left = 0, right = INF - 1;
while(right - left + 1 > 3)
{
int d = (right - left) / 3;
int x = left + d;
int y = right - d;
bool better = Check(x, y, w);
if(better) left = x;
else right = y;
}
int ret = right;
for(int i = left; i < right; i++)
{
bool better = Check(i, i + 1, w);
if(!better)
{
ret = i;
break;
}
}
ans[w] = ret;
}

inline void Solve()
{
//printf("0 0\n");
ans[1] = 0;
Work(0);
Work(1);

cout << "A " << ans[0] << ' ' << ans[1] << endl;
//printf("A %d %d\n", ans[0], ans[1]);
}

int main()
{
//freopen("", "r", stdin);
Solve();
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: