It seems that the recent physical condition is not very good ah ...
Recently unexpectedly had one to stay up late, then the heart began to feel uncomfortable, I do not want to have heart disease ah, labor and capital also want to score. ==b
First is the first question, the hand speed is some, the brain is also slow some, then return to God, woc,1600 personal past ... Although it is 1 a, but the time is too long, so I did not come back to the topic and see.
A. Case of the zeros and ones time limit/test 1 second memory limit per test 256 megabytes input standard input output Standard output
Andrewid The Android is a galaxy-famous detective. In, he likes to strings containing zeros and ones.
Once he thought about a string of length n consisting of zeroes and ones. Consider the following operation:we choose any two adjacentpositions in the string, and if one them contains 0, and the O Ther contains 1, then we are allowed to remove this two digits from the string, obtaining a string of length n-2 as a R Esult.
Now Andreid thinks about what is the minimum length of the string This can remain after applying the described Operation s Everal Times (possibly, zero)? Help him to calculate this number. Input
The ' The ' input contains a single integer n (1≤n≤2 105), the length of this string that Andreid has.
The second line contains the string of length n consisting only from zeros and ones. Output
Output the minimum length of the "remain after applying" described operations several times. Sample Test (s) input
4
1100
Output
0
Input
5
01010
Output
1
Input
8
11101111
Output
6
Note
In the ' The ' the ' the ' the ' the ' possible to ' change ' the string like the following:.
In the second sample test it's possible to change the string like the following:.
In the third sample test it's possible to change the string like the following:.
The general meaning of this topic is:
Now this man has a string composed of 0 and 1, then if you encounter the next 0 and 1 together, then you can remove the two numbers, then the length of the string will be reduced by 2, and then continue to do this until you can not, and then ask you the length of the string at the end of how much.
At first I thought of the simulation, but because the data was too big and all of a sudden, so many people, so I think it is certainly not to do so ...
So here's the thing:
The maximum number of reductions is definitely 0 or 1, and then multiplied by 2, which is the maximum reduction in length.
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm >
#include <map>
using namespace std;
#define MAXN 222222
Char A[MAXN];
int main () {
int n;
scanf ("%d", &n);
scanf ("%s", a);
int tx,ty;
int num0,num1;
num0=num1=0;
for (int i=0;i<n;i++) {
if (a[i]== ' 0 ') num0++;
if (a[i]== ' 1 ') num1++;
}
int num=min (NUM0,NUM1);
int len=n-num*2;
printf ("%d\n", Len);
}
B. Case of Fake Numbers time limit/test 2 seconds memory limit per test 256 megabytes input standard input output Stan Dard output
Andrewid The Android is a galaxy-famous detective. He's now investigating-a case of frauds to make fake copies of the famous Stolp ' s gears, puzzles that are as famous as T He Rubik ' s cube once is.
Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers from 0 to n-1 in the counter-clockwise order. When you push a button, the "the" gear rotates clockwise, then the second gear, rotates counter-clockwise, the third GE Ar rotates clockwise.
Besides, each gear has exactly one active tooth. When a gear turns, a new active tooth was the one following after the current active tooth according to the direction of th E rotation. For example, if n = 5, and the active tooth are the one containing number 0, then clockwise rotation makes the tooth with n Umber 1 active, or the counter-clockwise rotating makes the tooth number 4 active.
Andrewid remembers that the real puzzle has the following property:you can push the button multiple times in such a way t Hat in the "end" of the numbers on the active teeth of the "gears from" to the "last form sequence 0, 1, 2, ..., n-1." Write a program of that determines whether the given puzzle are real or fake. Input
The contains integer n (1≤n≤1000)-the number of gears.
The second line contains n digits a1, A2, ..., an (0≤ai≤n-1)-the sequence of active teeth:the active tooth of the I-th gear contains number AI. Output
In a single line print "Yes" (without the quotes), if the given Stolp ' s gears puzzle are real, and ' No ' (without the quotes ) otherwise. Sample Test (s) input
3
1 0 0
Output
Yes
Input
5
4 2 1 4 3
Output
Yes
Input
4
0 2 3 1
Output
No
Note
In the ' The ' the ' the ' the ' the ' the ' the button ' for the ' the ' the sequence of active teeth would be 2 2 1 Push it for the second time and get 0 1 2.
Then is b problem, the topic read for a long time, finally found is a water title ~
The word is probably: you have to finish the 0~n-1 in order gear, if you can achieve this goal, then we will output yes, otherwise output No.
Probably means:
If that is a gear on the odd digit, it rotates clockwise, notice a detail, and when it is n-1, it returns to 0.
If it's a gear on an even digit, it rotates counterclockwise, and when it's 0 o'clock, it's going to go back to n-1.
If there is a loop section after many loops (that is, the same sequence as the previous one), then we think that this task is never going to be done.
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <
Map> using namespace std;
#define MAXN 1111 int A[MAXN],TT[MAXN];
int main () {int n;
scanf ("%d", &n);
for (int i=1;i<=n;i++) {scanf ("%d", &a[i]);
Tt[i]=a[i];
BOOL Ff=true;
#if 1 for (int i=1;i<=n;i++) {if (a[i]==i-1) continue;
else {ff=false;
Break
} if (FF) {puts ("Yes");
return 0;
#endif while (1) {ff=true;
BOOL Flag=true;
for (int i=1;i<=n;i++) {if (i%2) {if (tt[i]==n-1) tt[i]=0;
else tt[i]++;
else if (i%2==0) {if (tt[i]==0) tt[i]=n-1;
else tt[i]--;
for (int i=1;i<=n;i++) {if (tt[i]==i-1) continue;
else {ff=false;
Break } if (ff) {printf ("yes\n");
Break
for (int i=1;i<=n;i++) {if (A[i]!=tt[i]) {flag=false;
Break
} if (flag) {printf ("no\n");
Break }
}
}
C. Case of Matryoshkas time limit/test 2 seconds memory limit per test 256 megabytes input standard input output stand ARD output
Andrewid The Android is a galaxy-famous detective. The IT now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of N Matryoshka dolls which can be nested one into another. The Matryoshka dolls are numbered from1 to N. A matryoshka with a smaller number can is nested in a matryoshka with a higher number, two Matryoshkas can is not directly Nested in the same doll, but there May is chain nestings, for example, 1→2→4→5.
In one second, your can perform one of the two following operations:having a matryoshka a that's isn ' t nested in no other M Atryoshka and a Matryoshka B, such that B doesn ' t contain the any other Matryoshka and isn't nested in the any other Matryoshka, You'll put a in B; Having a matryoshka a directly contained in Matryoshka B, such that B are not nested Out OFB.
According to the modern aesthetic norms Matryoshka dolls at display were assembled in a specific configuration, i.e. a s several separate chains of nested Matryoshkas, but the criminal, following the mysterious nd assembled them into a single large chain (1→2→ ... →N). In order to continue the investigation Andrewid needs to know in what minimum time it are possible to perform this action. Input
The contains integers