周日刚打算午觉躺下,舍友说今天有比赛,就凑个热闹..
A - Picking&Dancing
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
Yitong_Qin and Xiaoyu_Chen are playing a game.There are $N$ stones placed on the ground,forming a sequence.
Thr stones are labeled from 1 to N. Yitong_Qin and Xiaoyu_Chen in turns take exactly two consecutive stones on the ground
until there are no consecutive stones on the ground.That is,each player can take stone $i$ and stone $i+1$,
where $1 \leq i \leq n-1$.If the number of stones left is odd,Yitong_Qin wins ,so Xiaoyu_Chen has to dance.
Otherwise Xiaoyu_Chen wins Yitong_Qin has to dance.
Input
The input contains an integer $N(1 \leq N \leq 5000)$,the number of stones.
Output
Output the guy has to dance.
Sample input and output
Sample Input | Sample Output |
---|---|
1 | Xiaoyu_Chen |
2 | Yitong_Qin |
5 | Xiaoyu_Chen |
Source
Solution
- Q 和C依次取两个剩下是奇数1的话C跳舞,偶数0的话Q跳舞
- 取模判定即可
#include<iostream>
using namespace std;
int main(void)
{
int n;
cin >> n;
if (n % 2 == 1)
cout << "Xiaoyu_Chen";
else
cout << "Yitong_Qin";
return 0;
}
VC++6.0编译测试结果:
B - string
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
A string consisting of lowercase letters,two adjacent character can be combined if and only if this two character are different.
And the combined character is the latter one. (such as "ac" can be combined, and the result is "a").
Now your work is to combined the character as more as possible so that finally the string can be shortest.
Input
A string consisting of lowercase letters. (1≤length≤200000)
Output
a positive integer x means the finally length of string.
Sample input and output
Sample Input | Sample Output |
---|---|
abcd | 1 |
aac | 2 |
Solution
- 前后两个字母融合等于前面的字母,按顺序走,说明最关键的就是一开始的那个字母
- 若输入字母为“aabcadaa”,则输出为2,因为即使b之后还有a
但是从b往后的字母都可以被b融合,得到aab,最后留下aa; - 所以答案就是连续的开头字母个数 //fgets用来输入字符串,而l的长度比字符长度多1
#include<iostream>
#include<string.h>
using namespace std;
#define N 200000
char a[N];
int main(void)
{
int i, l, s=1;
fgets(a, N + 1, stdin);
l = strlen(a);
for (i = 0; i < l-1; i++)
{
if (a[i] == a[i + 1])
{
s++;
}
else
{
break;
}
}
cout << s;
return 0;
}
VC++6.0编译测试结果:
C - How To Get Twenty-four?
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
It is nearly the December 7, Mr.Flower's birthday. His roommates have already prepared a precious gift for him.
But they have a simple exam for Mr.Flower, only if he get the answer can he receive the gift. The question is described as follow:
-
Mr.Flower's roommates will give him a integer N, that means he get N '7', for example if N=4, Mr.Flower get '7','7','7','7';
-
Then Mr.Flower should ues these number to calculate '24';
-
Mr.Flower could only ues '+', '-', '*', '(' , ')' and '/';
This problem is very easy for Mr.Flower, but he should prepare for CET-6.
You are the best friend of Mr.Flower, so he wants you to tell him whether he can get '24'.
Input
there is one numbers $N$, the number of '7' that you have$(1 \leq N \leq 1000)$.
Output
if you can get '24' with N '7',than output "YES"(without quote), if you can't do it, output "NO".
Sample input and output
Sample Input | Sample Output |
---|---|
1 | NO |
2 | NO |
6 | YES |
Hint
对于样例三 (7×7×7−7)/(7+7)=24
Solution
- 已知无法构成由7的个数小于等于5,通过加减乘除组成一个24点的情况
- 6个7的情况Hint有说明(称之为6式)
- 7个7的情况,拼凑得:“7+7+7+(7+7+7)/7 ”
- 由6式衍生出8个7的情况即:“6式+(7-7)”
- 在衍生出9个及其以上的情况“6式+(7-7)/(7..)”
- 所以,只要n的个数超过6个,n个7通过加减乘除可得到24
#include<iostream>
using namespace std;
int main(void)
{
int n;
cin >> n;
if (n >= 6)
cout << "YES";
else
cout << "NO";
return 0;
}
VC++6.0编译测试结果:
/* -----------------------------------------------分隔符---------------------------------------------------------------*/