首页 > 代码库 > 2017-4-14:Train-第四届福建省赛

2017-4-14:Train-第四届福建省赛

G - Easy Game(水题)

Fat brother and Maze are playing a kind of special (hentai) game on a string S. Now they would like to count the length of this string. But as both Fat brother and Maze are programmers, they can recognize only two numbers 0 and 1. So instead of judging the length of this string, they decide to judge weather this number is even.

Input

The first line of the date is an integer T, which is the number of the text cases.

Then T cases follow, each case contains a line describe the string S in the treasure map. Not that S only contains lower case letters.

1 <= T <= 100, the length of the string is less than 10086

Output

For each case, output the case number first, and then output “Odd” if the length of S is odd, otherwise just output “Even”.

Sample Input

4

well

thisisthesimplest

problem

inthiscontest

Sample Output

Case 1: Even

Case 2: Odd

Case 3: Odd

Case 4: Odd

Means:

给你一串字符,问你这串字符的长度是奇数还是偶数

Solve:

一个水题,不是吗

Code:

技术分享
 1 #include <cstdio> 2 #include <cstring> 3 using namespace std; 4 #define CLR(x , v)        memset(x , v , sizeof(x)) 5 #define CASE(x)            printf("Case %d: " , x) 6 static const int MAXN = 10086; 7 char data[MAXN]; 8 int main() 9 {10     int t;11     scanf("%d" , &t);12     for(int c = 1 ; c <= t ; ++c)13     {14         CLR(data , \0);15         scanf(" %s" , data);16         int len = strlen(data);17         CASE(c);18         if(len & 1)19             printf("Odd\n");20         else21             printf("Even\n");22     }23 }
View Code

 H - A-B Game(数学,贪心)

Fat brother and Maze are playing a kind of special (hentai) game by two integers A and B. First Fat brother write an integer A on a white paper and then Maze start to change this integer. Every time Maze can select an integer x between 1 and A-1 then change A into A-(A%x). The game ends when this integer is less than or equals to B. Here is the problem, at least how many times Maze needs to perform to end this special (hentai) game.

Input

The first line of the date is an integer T, which is the number of the text cases.

Then T cases follow, each case contains two integers A and B described above.

1 <= T <=100, 2 <= B < A < 100861008610086

Output

For each case, output the case number first, and then output an integer describes the number of times Maze needs to perform. See the sample input and output for more details.

Sample Input

2

5 3

10086 110

Sample Output

Case 1: 1

Case 2: 7

Means:

给你一个数A,一个数B,问你最少经过多少次可以使得A小于等于B,A的操作为A - (A % x) , 其中x[1 , A - 1]的任意一个数。

Solve:

贪心,每次取X最大,那么什么时候X最大,X = A / 2 + 1的时候,因为A/2的话,偶数就GG,然后就能保证每次A减去的就是最大的,剩下的A就是A/2 + 1

Code:

技术分享
 1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 using namespace std; 5 #define CLR(x , v)        memset(x , v , sizeof(x)) 6 #define CASE(x)            printf("Case %d: " , x) 7 typedef unsigned long long LL; 8 int t; 9 LL a , b;10 int main()11 {12     scanf("%d" , &t);13     for(int c = 1 ; c <= t ; ++c)14     {15         LL ans = 0;16         scanf("%lld%lld" , &a , &b);17         while(a > b)18         {19             a = a >> 1 | 1;20             ++ans;21         }22         CASE(c);23         printf("%d\n" , ans);24     }25 }
View Code

 

2017-4-14:Train-第四届福建省赛