BNU19907 UVA11489 Integer Game
2016-10-19 17:17
281 查看
Integer Game
Time Limit: 1000msMemory Limit: 131072KB
This problem will be judged on UVA. Original ID: 11489
64-bit integer IO format: %lld Java class name: Main
Prev
Submit Status Statistics Discuss
Next
Type:
None
NoneGraph Theory 2-SAT
Articulation/Bridge/Biconnected Component
Cycles/Topological Sorting/Strongly Connected Component
Shortest Path Bellman Ford
Dijkstra/Floyd Warshall Euler Trail/Circuit
Heavy-Light Decomposition
Minimum Spanning Tree Stable Marriage Problem
Trees Directed Minimum Spanning Tree
Flow/Matching Graph Matching
Bipartite Matching
Hopcroft–Karp Bipartite Matching Weighted Bipartite Matching/Hungarian Algorithm
Flow Max Flow/Min Cut
Min Cost Max Flow
DFS-like Backtracking with Pruning/Branch and Bound
Basic Recursion IDA* Search
Parsing/Grammar Breadth First Search/Depth First Search
Advanced Search Techniques
Binary Search/Bisection Ternary Search
Geometry Basic Geometry
Computational Geometry
Convex Hull Pick's Theorem
Game Theory Green Hackenbush/Colon Principle/Fusion Principle
Nim Sprague-Grundy Number
Matrix Gaussian Elimination
Matrix Exponentiation
Data Structures Basic Data Structures
Binary Indexed Tree Binary Search Tree
Hashing Orthogonal Range Search
Range Minimum Query/Lowest Common Ancestor Segment Tree/Interval Tree
Trie Tree Sorting
Disjoint SetString
Aho Corasick Knuth-Morris-Pratt
Suffix Array/Suffix TreeMath
Basic Math Big Integer Arithmetic
Number Theory Chinese Remainder Theorem
Extended Euclid Inclusion/Exclusion
Modular Arithmetic Combinatorics
Group Theory/Burnside's lemma Counting
Probability/Expected Value
Others Tricky Hardest
Unusual Brute Force
Implementation Constructive Algorithms
Two Pointer Bitmask
Beginner Discrete Logarithm/Shank's Baby-step Giant-step Algorithm
Greedy Divide and Conquer
Dynamic Programming
Tag it!
[PDF Link]
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, its 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 |
给出一个数字串N,两个人轮流从中取出一个数字,要求每次取完之后剩下的数是3的倍数,不能取着输.如果两个游戏者都足够聪明,谁会取胜,输入非空数字串N(N由不超过1000个非0的数字组成),如果先手胜,输出S,否则输出T.
#include<bits/stdc++.h> using namespace std; int main() { char str[1010]; int t,h,sum,flag,k,i,g; scanf("%d",&t); for(h=1; h<=t; h++) { scanf("%s",str); sum=0; k=0; for(i=0; str[i]!=0; i++) { sum+=str[i]-48; if((str[i]-48)%3==0) k++; } printf("Case %d: ",h); if(sum%3!=0) { g=sum%3; flag=0; for(i=0; str[i]!=0; i++) if((str[i]-48)%3==g) flag=1; if(!flag) { printf("T\n"); continue; } if(k%2==0) { printf("S\n"); continue; } else { printf("T\n"); continue; } } else { if(k&1) { printf("S\n"); continue; } else { printf("T\n"); continue; } } } return 0; }
相关文章推荐
- UVA - 11489 Integer Game
- Uva 11489 - Integer Game 解题报告(简单推理)
- Integer Game(UVA11489)3的倍数
- UVA 11489 - Integer Game 博弈
- Integer Game(UVA11489)3的倍数
- UVA 11489 - Integer Game 博弈
- UVa 11489 - Integer Game
- UVA 11489- Integer Game
- UVA11489Integer Game博弈
- uva 11489 Integer Game
- UVa 11489 Integer Game
- UVA 11489 - Integer Game(数论+博弈)
- UVA 11489 Integer Game——博弈
- UVa 11489 - Integer Game (简单博弈 脑筋急转弯)
- UVa11489 - Integer Game(博弈)
- UVa 11489 Integer Game (博弈&想法题)
- Uva11489 Integer Game
- UVA 11489 Integer Game(博弈)
- uva 11489 - Integer Game(水题)
- uva 11489 - Integer Game(数论)