Codeforces1137D Cooperative Game

Description

Input

Output

Solution

就是你有10个棋子,有一条边数为t的链和一个边数为c的环(t和c未知)组成的有向图,每次操做能够让一些棋子移动一步,让你在不超过\(3 \times (t+c)\)次操做下让全部点移动到链和环链接的点处
首先咱们考虑两个点动,剩下的点走t步走到终点
设0每两次操做走一次,1每次操做都走
当0走到链接处时,花费了2t步,还剩(t+3c)步
标记该点为0,而后按顺序给每一个点按1~c-1标点
显然1的位置在(t%c)处
则1追上0须要2*(c-t%c)步
此时的位置应该是(c-t%c)
而再走t步的位置就回到了0
总步数(3t+(2c-t%c))<\(3 \times (t+c)\)oop

#include <cstdio>
#include <algorithm>
#define open(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
char s[21];
int pd()
{
    int t;
    scanf("%d",&t);
    for (int i=1;i<=t;i++)
        scanf("%s",s);
    return t;
}
int main()
{
    open("cooperative");
    while (true)
    {
        printf("next 0 1\n");
        fflush(stdout);
        pd();
        printf("next 1\n");
        fflush(stdout);
        if (pd()==2) break;
    }
    while (true)
    {
        printf("next 0 1 2 3 4 5 6 7 8 9\n");
        fflush(stdout);
        if (pd()==1) 
        {
            printf("done");
            fflush(stdout);
            exit(0);
        }
    }
    return 0;
}
相关文章
相关标签/搜索