CF 1138 F. Cooperative Game

F. Cooperative Game

链接

题意:

有10个玩家,开始所有玩家在home处,每次可以让一些玩家沿着边前进一步,要求在3(t+c)步以内,到达终点。

 

分析:

  很有意思的一道题。我们构造一种走的方式,设玩家有A,B和剩下的。

  1、首先A走一步,然后A,B同时走一步,直到AB相遇。(A,B一定会相遇,A先进入环上,然后B进入环上后,没此操作AB之间的距离减少1)

  2、然后A,B,和剩下的所有玩家同时走,直到相遇。相遇的点就是要找到的点。

  为什么这样是对的?

  设B进入环上后又走了x步,那么B=x+t,A=x+kc+t,即A进入环后转了k圈。A=2B,那么有x+kc+t=2x+2t;在模c的意义下:-x≡t (mod c),即c-x≡t (mod c)。c-x就是AB还要走的步数,t就是剩下的玩家需要走的步数。  

代码:

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;

inline int read() {
    int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
    for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';return x*f;
}

char s[15];
int IN() {
    int x = read();
    for (int i = 1; i <= x; ++i) scanf("%s", s);
    return x;
}
int main() {
    while (1) {
        puts("next 0"); fflush(stdout); IN();
        puts("next 0 1"); fflush(stdout); 
        if (IN() == 2) break;
    }
    while (1) {
        puts("next 0 1 2 3 4 5 6 7 8 9"); fflush(stdout);
        if (IN()==1) break;
    }
    puts("done"); fflush(stdout);
    return 0;
}

 

posted @ 2019-03-13 18:01  MJT12044  阅读(272)  评论(0编辑  收藏  举报