Codeforces 1375 F. Integer Game(交互,博弈)

This is an interactive problem.

Anton and Harris are playing a game to decide which of them is the king of problemsetting.

There are three piles of stones, initially containing 𝑎, 𝑏, and 𝑐 stones, where 𝑎, 𝑏, and 𝑐 are distinct positive integers. On each turn of the game, the following sequence of events takes place:

The first player chooses a positive integer 𝑦 and provides it to the second player.
The second player adds 𝑦 stones to one of the piles, with the condition that he cannot choose the same pile in two consecutive turns.
The second player loses if, at any point, two of the piles contain the same number of stones. The first player loses if 1000 turns have passed without the second player losing.

Feeling confident in his skills, Anton decided to let Harris choose whether he wants to go first or second. Help Harris defeat Anton and become the king of problemsetting!

Input
The first line of input contains three distinct positive integers 𝑎, 𝑏, and 𝑐 (1≤𝑎,𝑏,𝑐≤109) — the initial number of stones in piles 1, 2, and 3 respectively.

Interaction
The interaction begins by reading the integers 𝑎, 𝑏 and 𝑐.

After reading the integers, print a single line containing either “First” or “Second”, denoting who you want to play as (as first or second correspondently).

On each turn, the first player (either you or the judge) must print a positive integer 𝑦 (1≤𝑦≤1012).

Then, the second player must print 1, 2, or 3, indicating which pile should have 𝑦 stones added to it. From the second turn onwards, the pile that the second player chooses must be different from the pile that they chose on the previous turn.

If you are playing as Second and complete 1000 turns without losing, or if you are playing as First and the judge has determined that it cannot make a move without losing, the interactor will print 0 and will finish interaction. This means that your program is correct for this test case, and you should exit immediately.

If you are playing as First and complete 1000 turns without winning, or if you are playing as Second and print a move that makes two piles have the same number of stones, or if you output an invalid move as either player, the interactor will print −1 and will finish interaction. You will receive a Wrong Answer verdict. Make sure to exit immediately to avoid getting other verdicts.

After printing something do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

fflush(stdout) or cout.flush() in C++;
System.out.flush() in Java;
flush(output) in Pascal;
stdout.flush() in Python;
see documentation for other languages.
In this problem, hacks are disabled.

Example
inputCopy
5 2 6

3

0
outputCopy

First
2

3
Note
In the sample input, the piles initially have 5, 2, and 6 stones. Harris decides to go first and provides the number 2 to Anton. Anton adds 2 stones to the third pile, which results in 5, 2, and 8.

In the next turn, Harris chooses 3. Note that Anton cannot add the stones to the third pile since he chose the third pile in the previous turn. Anton realizes that he has no valid moves left and reluctantly recognizes Harris as the king.

題意:
給你3個堆石子。
先手並每次給一個數字,後手選擇一個石堆加上這個數字,後手連續兩個回合不能選一樣的數字。出現石堆數目相同則先手勝利,當1000回合還沒有決出勝負則後手勝利
你可以選擇先手或者後手與系統進行交互。

思路:
最優策略爲:你選擇先手。
三堆石子數目爲:a,b,c。

第一輪給出數字y1y1,且這個數字很大(使得可以忽略原來數字的影響)。
後手選aa

第二輪你選擇數字y2y2,需要滿足b+y2>a+y1b+y2>a+y1
後手選bb

第三輪你選擇y3y3

因爲此時三堆石子的大小爲 b+y2>a+y1>cb+y2>a+y1>c

則後手此時失敗的條件爲
c+y3=a+y1c+y3=a+y1,選擇cc的結果
a+y1+y3=b+y2a+y1+y3=b+y2,選擇aa的結果
此時不能再選擇bb了。

然後解方程就好了。

#include <cstdio>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
 
using namespace std;
 
typedef long long ll;
const int maxn = 3e5 + 7;
 
ll a[10];
 
int main() {
    for(int i = 1;i <= 3;i++) {
        scanf("%lld",&a[i]);
    }
    
    printf("First\n");
    
    ll y1 = 1e10;
    printf("%lld\n",y1);
    fflush(stdout);
    
    int res1;scanf("%d",&res1);
    a[res1] += y1;
    
    ll num = 0;
    for(int i = 1;i <= 3;i++) {
        if(i == res1) continue;
        num += a[i];
    }
    
    ll y2 = 2 * a[res1] - num;
    
    printf("%lld\n",y2);
    fflush(stdout);
    
    int res2;
    scanf("%d",&res2);
    a[res2] += y2;
    
    int res3;
    for(int i = 1;i <= 3;i++) {
        if(i == res1 || i == res2) continue;
        res3 = i;
    }
 
    ll y3 = a[res2] - a[res1];
    
    printf("%lld\n",y3);
    
    fflush(stdout);
    int zero;scanf("%d",&zero);
    
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章