Game Link: http://codeforces.com/contest/560
Pen field ...
A. Currency System in GeraldionTime limit per test:2 secondsmemory limit per test:256 megabytes
A Magic Island Geraldion, where Gerald lives, have its own currency system. It uses banknotes of several values. But the problem is, the system isn't perfect and sometimes it happens that Geraldionians cannot express a certain sum of Money with any set of banknotes. Of course, they can use any number of banknotes for each value. Such sum is calledunfortunate. Gerald Wondered:what is the minimumunfortunate sum?
Input
The first line contains number n (1?≤? N. ≤?1000)-the number of values of the banknotes that used in geraldion.
The second line contains n distinct space-separated numbersa1,? A2,?...,? An (1?≤? ) Ai? ≤?106)-the values of the banknotes.
Output
Print a single line-the minimum unfortunate sum. If There is no unfortunate sums, print ?-? 1.
Sample Test (s)Input
51 2 3) 4 5
Output
-1
The main idea: N kinds of banknotes each face value of AI, ask the smallest can not form the size of the face value
Title Analysis: There are 1 lost-1, No 1 lost 1
#include <cstdio>int main () {int ans = 1, n;scanf ("%d", &n), for (int i = 0; i < n; i++) {int get;scanf ("%d", &am P;get); if (get = = 1) ans =-1;} printf ("%d\n", ans);}
B. Gerald is into ArtTime limit per test:2 secondsmemory limit per test:256 megabytes
gerald bought, very rare paintings at the Sotheby ' s auction and he now wants to hang th EM on the wall. For this he bought a special board to attach it to the wall and place the paintings on the board. The Board has shape of a a 1?x? b 1 rectangle, the paintings has shape of A a 2?x? b 2 and a 3?x? b 3 rectangles.
Since The paintings is painted in the style of an abstract art, it does not matter exactly how they would be rotated, but STI ll, one side of both the board, and each of the paintings must is parallel to the floor. The paintings can touch each other and the edges of the board, but can not overlap or go beyond the edge of the board. Gerald asks whether it was possible to place the paintings on the board, or was the board he bought not large enough?
Input
The first line contains space-separated numbersa1 and b1 -the Sides of the board. Next lines contain numbersa2,? b2,? A3 andb3 -the sides of the paintings. All numbersai,? bi in the input is integers and fit into the range from1 to +.
Output
If the paintings can be placed on the wall, print "YES" (without the quotes), and if they cannot, print "no "(without the quotes).
Sample Test (s)Input
3 21 32 1
Output
YES
Input
5 53 33 3
Output
NO
Input
4 22 31 2
Output
YES
Note
That's how we can place the pictures in the first test:
And that's how we can does it in the third one.
Title: Three rectangles, give the edge length, ask after two can put in the first
Problem analysis: Too lazy to say, just a little bit of a situation
#include <cstdio> #include <algorithm>using namespace Std;int A1, A2, A3, B1, B2, B3;bool J (int x, int y) {retur N (x <= A1 && y <= B1 | | x <= b1 && y <= A1);} int main () {scanf ("%d%d%d%d%d", &A1, &b1, &a2, &b2, &a3, &B3); if (J (A2 + A3, Max (B2, b3)) | | J (B2 + B3, Max (A2, A3)) | | J (A2 + B3, Max (B2, A3)) | | J (A3 + b2, Max (B3, A2))) printf ("yes\n"); elseprintf ("no\n");}
C. Gerald ' s HexagonTime limit per test:2 secondsmemory limit per test:256 megabytes
Gerald got a very curious hexagon for his birthday. The boy found the angles of the hexagon is equal to. Then he measured the length of their sides, and found that each of the them are equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it.
He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he had got. But there were so many of them, Gerald lost the track of he counting. Help the boy count the triangles.
Input
The first and the single line of the input contains 6 space-separated integersa1,? A2,? A3,? A4,? A5 anda6 (1?≤? ) Ai? ≤?1000)-the lengths of the sides of the hexagons in centimeters in the clockwise or Der. It is guaranteed, the hexagon with the indicated properties and the exactly such sides exists.
Output
Print a single integer-the number of triangles with the sides of one 1 centimeter, to which the hexagon is split.
Sample Test (s)Input
1 1 1 1 1 1
Output
6
Input
1 2 1 2 1 2
Output
13
Note
This is what Gerald's hexagon looks like in the first sample:
And that's what's it looks like in the second sample:
The main topic: give the hexagon 6 side length, to find out how many sides of the side length of 1 positive triangles
The topic analysis: This question also has a kind of meaning, it complements the big positive triangle, the big positive triangle contains the small triangle number is the edge length ^2, arithmetic progression sums, because the side in order gives, through the rotation we can find the big side length equals a1+a2+a3, more out of the other three triangular side length for a1,a3,a5, So the final answer is (A1+A2+A3) ^2-a1^2-a3^2-a5^2
#include <cstdio> #include <cstring>int const MAX = 3005;int Fac[max];int Main () {for (int i = 1; I <= MAX; i+ +) Fac[i] = i * i;int a[7];for (int i = 1; I <= 6; i++) scanf ("%d", &a[i]);p rintf ("%d\n", fac[a[1] + a[2] + a[3]]-fa C[A[1]]-fac[a[3]]-fac[a[5]]);}
D. Equivalent StringsTime limit per test:2 secondsmemory limit per test:256 megabytes
Today on a lecture about strings Gerald learned a new definition of string equivalency. Stringsa and b of equal length is calledequivalent in one of the of the cases:
- They is equal.
- if we split string a into, halves of the same size a 1 and a Sub class= "Lower-index" >2 , and string b into/halves of the same s ize b 1 and b 2 , then one of the following is correct:
- a1 is equivalent tob1, and a2 is equivalent to b2
- a1 is equivalent tob2, and a 2 is equivalent to b1
As a home task, the teacher gave the strings to his students and asked to determine if they is equivalent.
Gerald have already completed this home task. Now it ' s your turn!
Input
The first and lines of the input contain the strings given by the teacher. Each of them have the length from1 to 200?000 and consists of lowercase Chinese letters. The strings has the same length.
Output
Print "YES" (without the quotes), if these, strings is equivalent, and "NO" (without the quotes) oth Erwise.
Sample Test (s)Input
Aabaabaa
Output
YES
Input
Aabbabab
Output
NO
Note
in the first sample you should split the first string into strings "aa " and "ba ", the second One-into strings "ab " and "aa ". "aa " is equivalent to "aa "; "ab " is equivalent to "ba " as "ab "=" a "+" b "," ba "=" b " + "a ".
In the second sample the first string can is splitted into strings "AA" and "BB", which is equivalent on Ly to themselves. That's why string "aabb" was equivalent only to itself and to string "Bbaa".
The main topic: to two strings, to determine whether they are equal, there are two cases of equality, one is directly equal, one is cut into the same length of two copies of the two substrings cross equal
Topic Analysis: The bare DFS, according to test instructions search on the line, if the current length is odd, directly return false, otherwise in two cases of search
#include <cstdio> #include <cstring>int const MAX = 250000;char A[max], B[max];bool DFS (char *p1, char *p2, int Len) { if (!strncmp (P1, p2, len)) return true; if (len% 2) return false; int n = LEN/2; if (Dfs (p1, p2 + N, N) && dfs (p1 + N, p2, n)) return true; if (Dfs (P1, p2, n) && dfs (p1 + N, p2 + N, N)) return true; return false;} int main () { scanf ("%s%s", A, b); printf ("%s\n", DFS (A, B, strlen (a))? "YES": "NO");}
The E-question will be mended ...
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Codeforces Round #313 (Div. 2) (ABCD)