【t063】最聪明的机器人

来源:互联网 发布:网络地板生产厂家 编辑:程序博客网 时间:2024/04/25 07:35

Time Limit: 1 second
Memory Limit: 128 MB

【问题描述】

【背景】 Wind设计了很多机器人。但是它们都认为自己是最强的,于是,一场比赛开始了~ 【问题描述】 机器人们都想知道谁是最聪明的,于是它们进行如下一种游戏。
这个游戏由2次机器人进行,2个机器人分别报出一个数n1,n2,谁报得大,就以这个数作为基数,并由它先开始,轮流进行如下操作:
选取一个不大于基数的素数或者1,从基数中扣掉它。谁把基数扣到0,谁就赢了。
为了公平,他们会进行10次比赛,请你分别输出这10次谁获胜了。
【时间限制】
每个测试点1s
【注释hint】
聪明的机器人当然会采取最优策略
【输入格式】

每组测试数据均有10行
每行2个数n1,n2 (n1,n2<=maxlongint n1<>n2)
【输出格式】

对每组测试数据输出10行,每行一个整数1或2
表示哪个机器人能获胜

Sample Input

10 9
8 10
10 7
6 10
8 9
9 7
6 9
9 5
3 2
1 2

Sample Output

1
2
1
2
2
1
2
1
1
2

【题目链接】:http://noi.qz5z.com/viewtask.asp?id=t063

【题解】

如果某个人遇到了数字4;
那么它肯定会输了;因为供它选择的数字有1,2,3;
选什么对方都能赢;
那么你遇到了4的倍数会怎么样呢?答案是不管怎么样你都会输,因为对方总有办法再让你遇到4的倍数;
因为你最少要减去1(%4==3),则对方再减去3你又遇到4的倍数了;而4的倍数不可能是质数,所以你没办法让对方遇到4的倍数;
那么最后对方总有办法让你遇到数字4,或者你直接让对方剩余的数字小于4直接赢了;
那么如果你遇到的数字不是4的倍数呢?
那么你总能让对方遇到4的倍数(描述如上);
则对方一定输;

最先遇到数字的那个人
如果是4的倍数他就输(对手赢);
如果不是4的倍数它就赢(对手输);

【完整代码】

#include <cstdio>#include <cstdlib>#include <cmath>#include <set>#include <map>#include <iostream>#include <algorithm>#include <cstring>#include <queue>#include <vector>#include <stack>#include <string>using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define LL long long#define rep1(i,a,b) for (int i = a;i <= b;i++)#define rep2(i,a,b) for (int i = a;i >= b;i--)#define mp make_pair#define pb push_back#define fi first#define se secondtypedef pair<int,int> pii;typedef pair<LL,LL> pll;void rel(LL &r){    r = 0;    char t = getchar();    while (!isdigit(t) && t!='-') t = getchar();    LL sign = 1;    if (t == '-')sign = -1;    while (!isdigit(t)) t = getchar();    while (isdigit(t)) r = r * 10 + t - '0', t = getchar();    r = r*sign;}void rei(int &r){    r = 0;    char t = getchar();    while (!isdigit(t)&&t!='-') t = getchar();    int sign = 1;    if (t == '-')sign = -1;    while (!isdigit(t)) t = getchar();    while (isdigit(t)) r = r * 10 + t - '0', t = getchar();    r = r*sign;}//const int MAXN = x;const int dx[5] = {0,1,-1,0,0};const int dy[5] = {0,0,0,-1,1};const double pi = acos(-1.0);int a,b;int main(){    //freopen("F:\\rush.txt","r",stdin);    rep1(i,1,10)    {        rei(a);rei(b);        int m = max(a,b);        if (!(m%4))        {            if (a>b)                puts("2");            else                puts("1");        }        else        {            if (a>b)                puts("1");            else                puts("2");        }    }    return 0;}
0 0