Integer Game(UVA 11489)

题目链接
由于每一次操作后余下的每个数位上的数的和为3的倍数,所以第一次取走的数和所有数位上的数的和对模3同余,并且此后每次取走的数都是3的倍数,可据此计算出总共操作的次数。
附上AC代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<set>
#include<vector>
#include<map>
#include<string>
#include<cmath>
#define pq priority_queue
#define Pi acos(-1.0)
#define MAXX 1000000007
using namespace std;
char s[1005];
int nums[15],total,l;
bool flag;
int main()
{
    int t,T=0;
    cin>>t;
    while(T++<t)
    {
        flag=0;
        total=0;
        l=0;
        memset(nums,0,sizeof(nums));
        scanf("%s",s);
        for(int i=0;s[i];i++)
        {
            l++;
            nums[s[i]-'0']++;
            total+=s[i]-'0';
        }
        if(nums[total%3])
        {
            nums[total%3]--;
            flag=1;
            l--;
        }
        else
        {
            if(nums[total%3+3])
            {
                nums[total%3+3]--;
                flag=1;
                l--;
            }
            else
            {
                if(nums[total%3+6])
                {
                    nums[total%3+6]--;
                    flag=1;
                    l--;
                }
                else
                {
                    if(nums[total%3+9])
                    {
                        nums[total%3+9]--;
                        flag=1;
                        l--;
                    }
                }
            }
        }
        if((nums[0]+nums[3]+nums[6]+nums[9])%2)
            flag=!flag;
        l-=(nums[0]+nums[3]+nums[6]+nums[9]);
        if(l==1)
            flag=!flag;
        printf("Case %d: ",T);
        if(flag)
            cout<<'S'<<endl;
        else
            cout<<'T'<<endl;
    }
    return 0;
}

Memory: 0 KB Time: 0 MS
Language: C++ 4.8.2 Result: Accepted

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值