简单博弈

发布时间:2017-3-24 0:43:53 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"简单博弈",主要涉及到简单博弈方面的内容,对于简单博弈感兴趣的同学可以参考一下。

I Integer Game     Two players, S and T, are playing a game where they make alternate moves. S plays first.  In this game, they start with an integer N. In each move, a player removes one digit from the integer and passes the resulting number to the other player. The game continues in this fashion until a player finds he/she has no digit to remove when that player is declared as the loser. With this restriction, it’s obvious that if the number of digits in N is odd then S wins otherwise T wins. To make the game more interesting, we apply one additional constraint. A player can remove a particular digit if the sum of digits of the resulting number is a multiple of 3 or there are no digits left. Suppose N = 1234. S has 4 possible moves. That is, he can remove 1, 2, 3, or 4.  Of these, two of them are valid moves. - Removal of 4 results in 123 and the sum of digits = 1 + 2 + 3 = 6; 6 is a multiple of 3. - Removal of 1 results in 234 and the sum of digits = 2 + 3 + 4 = 9; 9 is a multiple of 3. The other two moves are invalid. If both players play perfectly, who wins? Input The first line of input is an integer T(T<60) that determines the number of test cases. Each case is a line that contains a positive integer N. N has at most 1000 digits and does not contain any zeros. Output For each case, output the case number starting from 1. If S wins then output ‘S’ otherwise output ‘T’. Sample Input                             Output for Sample Input 3 4 33 771 Case 1: S Case 2: T Case 3: T Problem Setter: Sohel Hafiz Special Thanks: Shamim Hafiz, Md. Arifuzzaman Arif AC代码: /* * Author: ****** * Created Time: 2013/8/31 20:53:34 * File Name: num.cpp * solve: num.cpp */ #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> #include<string> #include<map> #include<stack> #include<set> #include<iostream> #include<vector> #include<queue> //ios_base::sync_with_stdio(false); //#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; #define sz(v) ((int)(v).size()) #define rep(i, a, b) for (int i = (a); i < (b); ++i) #define repf(i, a, b) for (int i = (a); i <= (b); ++i) #define repd(i, a, b) for (int i = (a); i >= (b); --i) #define clr(x) memset(x,0,sizeof(x)) #define clrs( x , y ) memset(x,y,sizeof(x)) #define out(x) printf(#x" %d\n", x) #define sqr(x) ((x) * (x)) typedef long long LL; const int INF = 1000000000; const double eps = 1e-8; const int maxn = 30000; int sgn(const double &x) { return (x > eps) - (x < -eps); } char str[1009]; int used[5]; int main() { //freopen("in.txt","r",stdin); int T; scanf("%d",&T); int k = 1; while(T--) { clr(used); scanf("%s",str); int len = strlen(str); int sum = 0; int num = 0; for(int i = 0;i<len;++i) { sum += str[i] - '0'; int tmp = (str[i] - '0')%3; used[tmp]++; if((str[i] - '0')%3 == 0) num++; } int flags = 0; printf("Case %d: ",k++); if(len == 1) { flags = 1; printf("S\n"); continue; } int temp = sum%3; if(used[temp] == 0) { flags = 0; }else { len--; used[temp]--; if(len == 1) { flags = 0; }else { if(used[0]%2 == 0) { flags = 1; }else flags = 0; } } if(flags) printf("S\n"); else printf("T\n"); } return 0; }

上一篇:linux进程调度
下一篇:黑马程序员——Java基础---GUI

相关文章

关键词: 简单博弈

相关评论

本站评论功能暂时取消,后续此功能例行通知。

一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!

二、互相尊重,对自己的言论和行为负责。

好贷网好贷款