链接:​​click here~~​​​,密码:nyist
涉及字符串的题比较多,有一道题原先在codeforces做过,
【题解】

A - A and B and Chess


Time Limit:1000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u

Submit ​​Status​​​ ​​​ Practice​​​ ​​​ CodeForces 519A​


Description



A and B are preparing themselves for programming contests.

To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.

For each chess piece we know its weight:

  • the queen's weight is 9,
  • the rook's weight is 5,
  • the bishop's weight is 3,
  • the knight's weight is 3,
  • the pawn's weight is 1,
  • the king's weight isn't considered in evaluating position.

The player's weight equals to the sum of weights of all his pieces on the board.

As A doesn't like counting, he asked you to help him determine which player has the larger position weight.



Input



The input contains eight lines, eight characters each — the board's description.

The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters.

Q', the rook — as 'R', the bishop — as'B', the knight — as 'N', the pawn — as 'P', the king — as 'K'.

q', 'r', 'b', 'n', 'p', 'k', respectively.

.' (a dot).

not guaranteed



Output



White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal.



Sample Input



Input

...QK...


........


........


........


........


........


........


...rk...




Output

White




Input

rnbqkbnr


pppppppp


........


........


........


........


PPPPPPPP


RNBQKBNR




Output

Draw




Input

rppppppr


...k....


........


........


........


........


K...Q...


........




Output

Black




Hint



In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.

In the second test sample the weights of the positions of the black and the white pieces are equal to 39.

In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16.


【解题思路】


题目所述略长,其实看懂了非常容易理解:


统计大写字母和小写字母的对应的数字值,最后判断关系即可:


代码:


#include <iostream>
#include <stdio.h>
#include <map>
#include <stack>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int maxn=10005;
#define mem(a,b) memset(a,b,sizeof(a))
#define Max(a,b) a>b?a:b;
#define Min(a,b) a<b?a:b;
char mapp[maxn][1005];
int main()
{
int n=0,m=0,i,j;
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
{
scanf("%c",&mapp[i][j]);
}
getchar();
}
for(i=0;i<8;i++)
for(j=0;j<8;j++)
{
if(mapp[i][j]=='Q') m+=9;
if(mapp[i][j]=='R') m+=5;
if(mapp[i][j]=='B') m+=3;
if(mapp[i][j]=='N') m+=3;
if(mapp[i][j]=='P') m+=1;
if(mapp[i][j]=='q') n+=9;
if(mapp[i][j]=='r') n+=5;
if(mapp[i][j]=='b') n+=3;
if(mapp[i][j]=='n') n+=3;
if(mapp[i][j]=='p') n+=1;
}
if(m==n)
{
puts("Draw");
}
if(m>n) {puts("White");}
if(m<n) {puts("Black");}
}


B - A and B and Compilation Errors


Time Limit:2000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u

Submit ​​Status​​​ ​​​ Practice​​​ ​​​ CodeForces 519B​


Description



A and B are preparing themselves for programming contests.

B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.

n

However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change.

Can you help B find out exactly what two errors he corrected?



Input



n (3 ≤ n ≤ 105) — the initial number of compilation errors.

n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the errors the compiler displayed for the first time.

n space-separated integers b1, b2, ..., bn

n space-separated integers с1, с2, ..., сn



Output



Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.



Sample Input



Input

5


1 5 8 123 7


123 7 5 1


5 1 7




Output

8


123




Input

6


1 4 3 3 5 7


3 7 5 4 3


4 3 7 5




Output

1


3




Hint



In the first test sample B first corrects the error number 8, then the error number 123.

In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.

【解题思路】:


题目看数据就懂了,只是不知道为什么这么出,首先想到的是求和相减,(或者直接模拟一遍)但是应该不会这么简单,感觉要用容器或者异或,但是实际可能是想难了。

代码:

#include <iostream>
#include <stdio.h>
#include <map>
#include <stack>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int maxn=10005;
#define mem(a,b) memset(a,b,sizeof(a))
#define Max(a,b) a>b?a:b;
#define Min(a,b) a<b?a:b;
char mapp[maxn][1005];
int a[1000000],b[1000000],c[1000000];
int main()
{
mem(a,0),mem(b,0),mem(c,0);
int n,m,i,j,k,l;
scanf("%d",&n);
int a1=0,a2=0,a3=0;
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
a1+=a[i];
}
for(i=0; i<n-1; i++)
{
scanf("%d",&b[i]);
a2+=b[i];
}
for(i=0; i<n-2; i++)
{
scanf("%d",&c[i]);
a3+=c[i];
}
printf("%d\n",a1-a2);
printf("%d\n",a2-a3);
}


C - A and B and Team Training


Time Limit:1000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u

Submit ​​Status​​​ ​​​ Practice​​​ ​​​ CodeForces 519C​


Description



A and B are preparing themselves for programming contests.

An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the next team training A decided to make teams so that newbies are solving problems together with experienced participants.

A believes that the optimal team of three people should consist of one experienced participant and two newbies. Thus, each experienced participant can share the experience with a large number of people.

However, B believes that the optimal team should have two experienced members plus one newbie. Thus, each newbie can gain more knowledge and experience.

As a result, A and B have decided that all the teams during the training session should belong to one of the two types described above. Furthermore, they agree that the total number of teams should be as much as possible.

n experienced members and m



Input



n and m (0 ≤ n, m ≤ 5·105) — the number of experienced participants and newbies that are present at the training session.



Output



Print the maximum number of teams that can be formed.



Sample Input



Input

2 6




Output

2




Input

4 5




Output

3




Hint



Let's represent the experienced players as XP and newbies as NB.

In the first test the teams look as follows: (XP, NB, NB), (XP, NB, NB).

In the second test sample the teams look as follows: (XP, NB, NB), (XP, NB, NB), (XP, XP, NB).


【解题思路】:

题目看懂就明白了:

给出 n 个  experienced participants  和 m 个 newbies ,需要组成尽量多的组,组由3个人组成。有两种组合方式:(1)1 个 experienced participant 和 2 个  newbie  (2)2 个 experienced participant 和 1 个  newbie。问最多能组成的组数是多少组。 (排列组合)

如果大的数不比小的数达到两倍以上的话,即满足 ,


 

ps:这样写比较直观


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
int n, m;
scanf("%d %d",&n,&m);
if(m>=2*n)
{
cout<<n<<endl;
}
else if(n>=2*m)
{
cout<<m<<endl;
}
else{
cout<<(m+n)/3<<endl;
}
return 0;
}


F - DNA Alignment


Time Limit:2000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u

Submit ​​Status​​​ ​​​ Practice​​​ ​​​ CodeForces 520C​


Description



Vasya became interested in bioinformatics. He's going to write an article about similar cyclic DNA sequences, so he invented a new method for determining the similarity of cyclic sequences.

s and t have the same length n, then the function h(s, t) is defined as the number of positions in which the respective symbols of s and t are the same. Function h(s, t) can be used to define the function of Vasya distance ρ(s, t):



where 

 is obtained from string 

s, by applying left circular shift  i times. For example, ρ("AGC", "CGT") =  h("AGC", "CGT") + h("AGC", "GTC") + h("AGC", "TCG") +  h("GCA", "CGT") + h("GCA", "GTC") + h("GCA", "TCG") +  h("CAG", "CGT") + h("CAG", "GTC") + h("CAG", "TCG") =  1 + 1 + 0 + 0 + 1 + 1 + 1 + 0 + 1 = 6 s of length n on the Internet. Now he wants to count how many strings t there are such that the Vasya distance from the string s attains maximum possible value. Formally speaking, t must satisfy the equation: 

.

109.


Input


n (1 ≤ n ≤ 105).

n, consisting of characters "ACGT".


Output


109.


Sample Input


Input

1

C


Output

1


Input

2

AG


Output

4


Input

3

TTT


Output

1


Hint


t1 and t2 values ρ(s, t1) и ρ(s, t2) are maximum among all possible t, then both strings must be taken into account in the answer even if one of them can be obtained by a circular shift of another one.

ρ("C", "C") = 1, for the remaining strings t of length 1 the value of ρ(s, t)

ρ("AG", "AG") = ρ("AG", "GA") = ρ("AG", "AA") = ρ("AG", "GG") = 4.

ρ("TTT", "TTT") = 27

【解题思路】

之前有印象,


题意:给一个由A,T,C,G组成的字符串s,求使函数ρ(s,t)最大的t的个数。易知,t应该由字符串s中个数最多的字母组成(总数最多的字母只有一个的时候很好理解,如果有多个字母的个数相同,那么就可以将这些个数相同的字母看成一个字母,这样是等价的),求出字母个数最多的种类数x,根据排列组合,答案就是x^n。

代码:


#include <iostream>
#include <stdio.h>
#include <map>
#include <stack>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int maxn=100100;
#define mem(a,b) memset(a,b,sizeof(a))
#define LL long long
#define Max(a,b) a>b?a:b;
#define Min(a,b) a<b?a:b;
char mapp[maxn][1005];
int a[10],b[100000];
const int mod=1e9+7;
int n,m,i,j,A,G,C,T;
char str[maxn];
int main()
{
// while(scanf("%d",&n))
// {
scanf("%d",&n);
getchar();
scanf("%s",str);
int ss=0;
for(int i=0; i<n; i++)
{
if(str[i]=='A') A++;
if(str[i]=='G') G++;
if(str[i]=='C') C++;
if(str[i]=='T') T++;
}
int m1=Max(A,G);
int m2=Max(C,T);
int maxx=Max(m1,m2);
if(A==maxx) ss++;
if(G==maxx) ss++;
if(C==maxx) ss++;
if(T==maxx) ss++;
LL ans=1;
for(int i=0; i<n; i++)
{
ans=(ans*ss)%mod;
}
printf("%lld\n",ans%mod);
}

E - 久违的月赛之一和 I - 久违的月赛之二,实在没思路。不知道题目要我们求的是什么,赛后看了解题报告:

 似乎一知半解:

参考博客: ​​http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380146d96864968d4e414c42246111c3aa6e07b22121980853a3c50f11e41bca770216c5d61aa98cf8a4ad6bc912d3bcd7a742613d20955c418dfdc4653d620e15aeaae12&p=8b2a9700959459b908e2962856&newp=9a7e8614ce904ead17bd9b7c4453d8304a02c70e3f98&user=baidu&fm=sc&query=fzu-+2139&qid=a3324cd5000853b1&p1=1​

大家如果有问题,想法,欢迎交流~~