UVA - 11489 Integer Game (博弈)
来源:互联网 发布:淘宝怎么一键复制宝贝 编辑:程序博客网 时间:2024/05/23 16:55
Two players, S and T, are playing a game where they makealternate moves.S plays first.
In this game, they start with an integer N. In each move, a player removesone 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 toremove when that player is declared as the loser.
With this restriction, it’s obvious that if the number of digits in Nis odd thenS wins otherwise T wins. To make the game moreinteresting, we apply one additional constraint. A player can remove aparticular digit if the sum of digits of the resulting number is a multiple of3 or there are no digits left.
Suppose N = 1234. S has 4 possible moves. That is, he canremove 1, 2, 3, or 4. Of these, two ofthem are valid moves.
- Removal of 4 results in 123 and the sum of digits = 1 + 2 + 3 = 6; 6 isa multiple of 3.
- Removal of 1 results in 234 and the sum of digits = 2 + 3 + 4 = 9; 9 is amultiple of 3.
The other two moves are invalid.
If both players play perfectly, who wins?
Input
Thefirst line of input is an integer T(T<60) thatdetermines the number of test cases. Each case is a line that contains apositive integerN. N has at most 1000 digits and does notcontain any zeros.
Output
Foreach case, output the case number starting from 1. If S wins then output ‘S’ otherwise output ‘T’.
Sample Input Output forSample 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
题意:给你一个数字串,两个人轮流从中取出一个数字,要求每次取完之后剩下各个位上的数字和是3的倍数,不能取或者没有数字取的为输,让你判断先手的胜负
思路:其实我们可以先统计各个位上对3取余的结果,显然在第一次的时候我们可以取走一个使得数为3的倍数,然后只能每次取3的倍数,3的倍数意思就是余数为0的数,依次的话判断能走步数的奇偶
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 1005;char str[maxn];int num[maxn];int main() {int t, cas = 1;scanf("%d", &t);while (t--) {scanf("%s", str);memset(num, 0, sizeof(num));int sum = 0;for (int i = 0; i < strlen(str); i++) {num[(str[i]-'0')%3]++;sum += str[i] - '0';}int step = 0;if (num[sum%3]) {step = 1;num[sum%3]--;}if (step)step += num[0];printf("Case %d: %c\n", cas++, step&1?'S':'T');}return 0;}
- UVA 11489 - Integer Game(数论+博弈)
- UVA - 11489 Integer Game (博弈)
- UVA 11489 Integer Game (博弈)
- UVA 11489 Integer Game(博弈,规律)
- UVA 11489 - Integer Game 博弈
- UVa:11489 Integer Game(博弈)
- UVA 11489 Integer Game(博弈)
- UVa 11489 - Integer Game (简单博弈 脑筋急转弯)
- UVa 11489 Integer Game (博弈&想法题)
- Integer Game(UVA 11489)
- UVA - 11489 Integer Game
- Uva 11489 - Integer Game
- UVa 11489 - Integer Game
- UVa 11489 Integer Game
- UVA 11489- Integer Game
- uva 11489Integer Game
- uva 11489 - Integer Game(水题)
- UVA 11489 Integer Game (逻辑推理)
- .net 服务 安装 卸载 命令行 bat cmd
- [命令技巧]mkdir -p
- 解决oracle语句中 含数字的字符串按数字排序问题
- Javascript刷新页面的几种方法
- 数据挖掘十大算法--浅谈Adaboost算法
- UVA - 11489 Integer Game (博弈)
- linux 查找目录或文件
- 为什么ListView点击反应迟钝
- CSSOM视图模式(CSSOM View Module)
- POJ——2250 Compromise
- 度金互联网金融社区:互联网金融未来的三种发展方向
- stat函数与结构体(文件信息)
- Android.mk中打印输出信息
- linux学习地址