专栏文章
题解:CF1137D Cooperative Game
CF1137D题解参与者 2已保存评论 1
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @miqnyr7e
- 此快照首次捕获于
- 2025/12/04 07:54 3 个月前
- 此快照最后确认于
- 2025/12/04 07:54 3 个月前
思路
想到可以让一个棋子走的更快,在环路上从后面追上另一个,一旦相遇,便停止。此时再让所有棋子向前走 步便可以达到目的。
证明
我们设走的慢的棋子在环路上走了 步,则它一共走了 步,另一个棋子走了 步,而我们知道,快的棋子一定比慢的多走了 的整数倍,所以 即 必定是 的整数倍。而此时,留在起点的棋子相距终点 步,在环上的两个棋子再走 步就能到达终点,所以可以让全部棋子一起向前走 步以达到目的。
代码
CPP#include<bits/stdc++.h>
using namespace std;
string st[21];
bool get(int p){
int n;
cin>>n;
for(int i=1;i<=n;i++)cin>>st[i];
return n!=p;
}
signed main(){
int t=0;
while(1){
t++;
cout<<"next 0"<<endl;
get(2);
cout<<"next 0 1"<<endl;
if(!get(2))break;
}
while(1){
cout<<"next ";
for(int i=0;i<10;i++)cout<<i<<" ";
cout<<endl;
if(!get(1))break;
}
cout<<"done"<<endl;
}
相关推荐
评论
共 1 条评论,欢迎与作者交流。
正在加载评论...