好像都说这次是送!分!的! 好吧,弱菜没资格说话、、、、、、、、、、 尽量把D,E 给搞出来、、
A. A and B and Chess
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.
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.
The white pieces are denoted as follows: the queen is represented is 'Q', the rook — as 'R', the bishop — as'B', the knight — as 'N', the pawn — as 'P', the king — as 'K'.
The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively.
An empty square of the board is marked as '.' (a dot).
It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on.
Print "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.
...QK... ........ ........ ........ ........ ........ ........ ...rk...
White
rnbqkbnr pppppppp ........ ........ ........ ........ PPPPPPPP RNBQKBNR
Draw
rppppppr ...k.... ........ ........ ........ ........ K...Q... ........
Black
简单的模拟。
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>
using namespace std;
char tt[15][15];
int main()
{
while(~scanf("%s",tt[1]))
{
int ansa = 0;
int ansb = 0;
//printf("%s\n",tt[1]);
for(int i = 2; i <= 8; i ++)
{
scanf("%s",tt[i]);
}
for(int i = 1; i <= 8; i ++)
{
for(int j = 0; j < 8; j ++)
{
if(tt[i][j] == 'Q')
{
ansa += 9;
}
else if(tt[i][j] == 'q')
{
ansb += 9;
}
else if(tt[i][j] == 'R')
{
ansa += 5;
}
else if(tt[i][j] == 'r')
{
ansb += 5;
}
else if(tt[i][j] == 'B' || tt[i][j] == 'N')
{
ansa += 3;
}
else if(tt[i][j] == 'b' || tt[i][j] == 'n')
{
ansb += 3;
}
else if(tt[i][j] == 'P')
{
ansa ++;
}
else if(tt[i][j] == 'p')
{
ansb ++;;
}
}
}
if(ansa == ansb)
printf("Draw\n");
else if(ansa > ansb)
printf("White\n");
else
printf("Black\n");
}
}
B. A and B and Compilation Errors
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.
Initially, the compiler displayed n compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake.
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?
The first line of the input contains integer n (3 ≤ n ≤ 105) — the initial number of compilation errors.
The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the errors the compiler displayed for the first time.
The third line contains n - 1 space-separated integers b1, b2, ..., bn - 1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one.
The fourth line contains n - 2 space-separated integers с1, с2, ..., сn - 2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one.
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.
5 1 5 8 123 7 123 7 5 1 5 1 7
8 123
6 1 4 3 3 5 7 3 7 5 4 3 4 3 7 5
1 3
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 <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>
using namespace std;
#define N 100010
int ttt[N];
int tt[N];
int t[N];
int main()
{
int n, a;
while(~scanf("%d",&n))
{
int cnt = 1;
int ans1 = 0;
int ans2 = 0;
memset(ttt, 0, sizeof(ttt));
memset(tt, 0, sizeof(tt));
memset(t, 0, sizeof(t));
for(int i = 0; i < n; i ++)
{
scanf("%d",&ttt[i]);
}
sort(ttt, ttt + n);
for(int i = 0; i < n - 1; i ++)
{
scanf("%d",&tt[i]);
}
sort(tt, tt + n - 1);
for(int i = 0; i < n; i ++)
{
if(ttt[i] != tt[i])
{
ans1 = ttt[i];
break;
}
}
for(int i = 0; i < n - 2; i ++)
{
scanf("%d",&t[i]);
}
sort(t, t + n - 2);
for(int i = 0; i < n - 1; i ++)
{
if(tt[i] != t[i])
{
ans2 = tt[i];
break;
}
}
printf("%d\n%d\n", ans1, ans2);
}
}
C. A and B and Team Training
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.
There are n experienced members and m newbies on the training session. Can you calculate what maximum number of teams can be formed?
The first line contains two integers n and m (0 ≤ n, m ≤ 5·105) — the number of experienced participants and newbies that are present at the training session.
Print the maximum number of teams that can be formed.
2 6
2
4 5
3
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).
这题为纯数学,我感觉我写麻烦了
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>
using namespace std;
int n, m;
int main()
{
while(~scanf("%d%d",&n,&m))
{
if(n == m)
{
printf("%d\n", (n + m)/3);
continue;
}
int tmp_2;
if(n < m)
{
tmp_2 = n;
n = m;
m = tmp_2;
}
if(m *2> n)
{
printf("%d\n", (n + m)/3);
continue;
}
int ans = 0;
int a1 = n/2;
//ans += a1;
if(a1 >= m)
{
ans += m;
}
else if(a1 < m)
{
ans += a1;
n = n - a1 * 2;
m = m - a1;
//int a2 = m/2;
if(m >= 2 && n)
ans ++;
}
printf("%d\n",ans);
}
}