1、ZYB's Biology
Problem Description
After getting 60 scores in NOIP ZYB(ZJ−267) begins to work with biological questions.Now he give you a
simple biological questions: he gives you a DNADNADNA sequence and a RNARNARNA sequence,then he asks
you whether the DNA sequence and the RNA sequence are matched.
The DNADNADNA sequence is a string consisted of A,C,G,T;The RNA sequence is a string consisted of A,C,G,U.
DNA sequence and RNA sequence are matched if and only if A matches U,T matches A,C matches G,G matches
C on each position.
Input
In the first line there is the testcase T.
For each teatcase:
In the first line there is one number N.
In the next line there is a string of length N,describe the DNA sequence.
In the third line there is a string of length NNN,describe the RNA sequence.
1≤T≤101,1≤N≤1001
Output
For each testcase,print YES or NO,describe whether the two arrays are matched.
Sample Input
2
4
ACGT
UGCA
4
ACGT
ACGU
Sample Output
YES
NO
分析:这是一个大水题,首先数据不大,直接可以枚举过,一点小技巧就是类似常量数组的使用问题,不做赘述,直
接上代码。
代码如下:
*#include <cstdio>
char s[19];
int main()
{
int t,n;
char s1[100],s2[100];
s[0]='U';
s[2]='G';
s[6]='C';
s[19]='A';//这里的处理便类似于常量数组
scanf("%d",&t);
while (t--)
{
int f=1;//标志变量的使用往往很有用
scanf("%d",&n);
scanf("%s",s1);
scanf("%s",s2);
for (int i=0;i<n;i++)
{
if (s[(s1[i]-'A')]!=s2[i]) {f=0;break;}
}
if (f) printf("YES\n");
else printf("NO\n");
}
return 0;
}
2、ZYB's Game
Problem Description
ZYB played a game named NumberBomb with his classmates in hiking:a host keeps a number in [1,N] in
mind,then players guess a number in turns,the player who exactly guesses X loses,or the host will tell
all the players that the number now is bigger or smaller than X.After that,the range players can guess
will decrease.The range is [1,N] at first,each player should guess in the legal range.
Now if only two players are play the game,and both of two players know the X,if two persons all use the
best strategy,and the first player guesses first.You are asked to find the number of X that the second
player will win when X is in [1,N].
Input
In the first line there is the number of testcases T.
For each teatcase:
the first line there is one number N.
1≤T≤1000001,1≤N≤100000001
Output
For each testcase,print the ans.
Sample Input
1
3
Sample Output
1
分析:这个题说水很水,说不水也很要命,反正我是挨着推了几个数试试,结果发现只有n是奇数时后手才能赢,而且
只有一个数字满足,便是最中间的那个数,偶数时必输
看看大神的解释:我们会发现这个模型其实是类比于左右两堆石子,每次可以在一堆里取任意多,取完的人胜利.当左右
两堆石子相同时,我们可以简单的
构造后手胜利的方法:即在另一堆石子中取走同样多的石子,否则,先手可以取一些石子使得两堆石子相同.所以,当N是
奇数输出1,否则输出0.
代码如下:
#include <cstdio>
int main()
{
int t,n,j;
scanf("%d",&t);
while (t--)
{
scanf("%d",&n);
if (n%2==0)
printf("0\n");
else printf("1\n");
}
return 0;
}
剩下的几个题就全失败了,但还是传了吧
3、ZYB's Premutation
Problem Description
ZYB has a premutation P,but he only remeber the reverse log of each prefix of the premutation,now he
ask you to restore the premutation.
Pair (i,j)(i<j) is considered as a reverse log if Ai>Aj is matched.
Input
In the first line there is the number of testcases T.
For each teatcase:
In the first line there is one number N.
In the next line there are NNN numbers Ai
,describe the number of the reverse logs of each prefix,
The input is correct.
1≤T≤51 ,1≤N≤500001
Output
For each testcase,print the ans.
Sample Input
1
3
0 1 2
Sample Output
3 1 2
4、ZYB's Tree
Problem Description
ZYB has a tree with N nodes,now he wants you to solve the numbers of nodes distanced no more than K for
each node. the distance between two nodes(x,y) is defined the number of edges on their shortest path in
the tree.
To save the time of reading and printing,we use the following way:
For reading:we have two numbers AAA and BBB,let fa(i) be the father of node i,fa(1)=0,fa(i)=(A∗i
+B)%(i−1)+1 for i∈[2,N]
For printing:let ansians_iansibe the answer of nodei,you only need to print the xor sum of all ans(i)
Input
In the first line there is the number of testcases T.
For each teatcase:
In the first line there are four numbers N,K,A,B
1≤T≤51 ,1≤N≤5000001,1≤K≤10,1≤A,B≤1000000
Output
For T lines,each line print the ans.
Please open the stack by yourself.
N≥100000 are only for two tests finally.
Sample Input
1
3 1 1 1
Sample Output
3
5、ZYB's Prime
Problem Description
After getting 600 scores in NOIP,ZYB(ZJ−267) creates a problem:you are given N numbers,now you are
asked to divide them into K groups(K≥1),the number of each group must be no less than 3,and put all
the numbers in a group into a ring,the sum of every two adjacent numbers must be a prime.ZYB want to
ask you whether the N numbers can be divided or not?
Input
In the first line there is the testcase T.
For each teatcase:
In the first line there is one number N. In the next line there are N numbers A(i)
1≤T≤50,1≤N≤200,1≤Ai≤200,for 60 cases N≤20.
Output
For each testcase,print the YES or NO.
Sample Input
2
7
3 4 8 9 1 1 1
3
1 2 3
Sample Output
YES
NO
分析:感觉这个题是素数环(DFS)的一个变形,本题在其中添加了分组,就转化为求多个素数小环的问题,然而还是
没做出来
素数环做的比较好的博客:http://www.cnblogs.com/dongsheng/archive/2012/08/15/2639452.html