URAL 1180 Stone Game 博弈 找规律 大数取模 除3取模

题意:两人依次从一堆石子中取2的幂次个数的石子,如1 2 4 8 16…,能取到最后一颗石子的获胜。输入n,若第一人获胜则输出1和他第一次至少取多少个石子,若第二人获胜输出2。(n很大,10的250次幂)

结论:n%3=0则第二人获胜,否则第一人获胜且第一次至少取n%3个

心得:博弈题没有思路的时候就先找规律,足够敏感:取模,2的幂次,斐波那契等等!纸上演算或者写个程序跑打表观察!

 http://acm.timus.ru/problem.aspx?space=1&num=1180

1180. Stone Game

Time limit: 1.0 second
Memory limit: 64 MB

Two Nikifors play a funny game. There is a heap of N stones in front of them. Both Nikifors in turns take some stones from the heap. One may take any number of stones with the only condition that this number is a nonnegative integer power of 2 (e.g. 1, 2, 4, 8 etc.). Nikifor who takes the last stone wins. You are to write a program that determines winner assuming each Nikifor does its best.

Input

An input contains the only positive integer number N (condition N ≤ 10250 holds).

Output

The first line should contain 1 in the case the first Nikifor wins and 2 in case the second one does. If the first Nikifor wins the second line should contain the minimal number of stones he should take at the first move in order to guarantee his victory.

Sample

input output
8
1
2

 

   char s[300];
    intsum=0;
   scanf("%s",s);
   for(int i=0; i<strlen(s); i++)
       sum+=(s[i]-'0');
   if(sum%3==0) printf("2\n");
    elseif (sum%3==1) printf("1\n1\n");
    elseprintf("1\n2\n");
   return 0;

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值