Codeforces Round #313 (Div. 2) (ABCDE ),

Source: Internet
Author: User

Codeforces Round #313 (Div. 2) (ABCDE ),

Match link: http://codeforces.com/contest/560



A. Currency System in Geraldiontime limit per test: 2 secondsmemory limit per test: 256 megabytes

A magic island Geraldion, where Gerald lives, has its own currency system. it uses banknotes of several values. but the problem is, the system is not 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 of each value. such sum is calledunfortunate. gerald wondered: what is the minimumunfo Rtunate sum?

Input

The first line contains numberN(1 digit ≤ DigitNLimit ≤ limit 1000)-the number of values of the banknotes that used in Geraldion.

The second line containsNDistinct space-separated numbersA1, bytes,A2, middle..., middle ,...,AN(1 digit ≤ DigitAILimit ≤ limit 106)-the values of the banknotes.

Output

Print a single line-the minimum unfortunate sum. If there are no unfortunate sums, print accept-limit 1.

Sample test (s) Input
51 2 3 4 5
Output
-1

Each face value of n kinds of banknotes is ai, and the smallest part of the face size cannot be


Question Analysis: 1-1, 1

#include <cstdio>int main(){int ans = 1, n;scanf("%d", &n);for(int i = 0; i < n; i++){int get;scanf("%d", &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 two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. for that he bought a special board to attach it to the wall and place the paintings on the board. the board has shape ofA1 Gbit/s × hourB1 rectangle, the paintings have shape ofA2 bytes × secondB2 andA3 bytes × hourB3 rectangles.

Since the paintings are painted in the style of abstract art, it does not matter exactly how they will be rotated, but still, one side of both the board, and each of the paintings must be 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 is possible to place the paintings on the board, Or is the board he bought not large enough?

Input

The first line contains two space-separated numbersA1 andB1-the sides of the board. Next two lines contain numbersA2, bytes,B2, bytes,A3 andB3-the sides of the paintings. All numbersAI, Bytes,BIIn the input are integers and fit into the range from1 to1000.

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 do it in the third one.

The three rectangles provide the side length. Can the last two be placed in the first one?


Question Analysis: It's just a bit of a problem.


#include <cstdio>#include <algorithm>using namespace std;int a1, a2, a3, b1, b2, b3;bool J(int x, int y){return (x <= a1 && y <= b1 || x <= b1 && y <= a1);}int main(){scanf("%d %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 out that all the angles of the hexagon are equal. then he measured the length of its sides, and found that each of them is 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 has got. but there were so much of them that Gerald lost the track of his counting. help the boy count the triangles.

Input

The first and the single line of the input contains 6 space-separated integersA1, bytes,A2, bytes,A3, bytes,A4, middle,A5 andA6 (1 digit ≤ DigitAILimit ≤ limit 1000)-the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that 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, into 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 it looks like in the second sample:

The length of six sides of a hexagonal triangle is displayed.


Question Analysis: This question also has some meanings. Make it into a big positive triangle. The number of small triangles contained in the big positive triangle is the side length ^ 2, and the sum of the arithmetic difference series, because the sides are given in order, by rotating, we can find that the length of the large side is equal to a1 + a2 + a3, and the length of the other three positive triangles is 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]);printf("%d\n", fac[a[1] + a[2] + a[3]] - fac[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. Two stringsAAndBOf equal length are calledequivalent in one of the two cases:

As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent.

Gerald has already completed this home task. Now it's your turn!

Input

The first two lines of the input contain two strings given by the teacher. Each of them has the length from1 to200 limit 000 and consists of lowercase English letters. The strings have the same length.

Output

Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise.

Sample test (s) Input
aabaabaa
Output
YES
Input
aabbabab
Output
NO
Note

In the first sample you shoshould 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" + "".

In the second sample the first string can be splitted into strings "aa" and "bb", that are equivalent only to themselves. that's why string "aabb" is equivalent only to itself and to string "bbaa ".


Give two strings to determine whether they are equal. If they are equal, one is directly equal, and the other is cut into two parts with the same length.


Question Analysis: You can search for bare DFS Based on the meaning of the question. If the current length is an odd number, false is returned directly. Otherwise, the search is performed in two cases.

This question is over water, and the location of T91 is changed in two cases... Orz, God character, but the string into char *, how can I go through


#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");}



E. Gerald and Giant Chesstime limit per test: 2 secondsmemory limit per test: 256 megabytes

Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place onHLimit × limitWField, and it is painted in two colors, but not like in chess. almost all cells of the field are white and only some of them are black. currently Gerald is finishing a game of giant chess against his friend Pollard. gerald has almost won, and the only thing he needs to win is to bring the pawn from the upper left corner of the board, where it is now standing, to the lower right corner. gerald is so Confident of Vicente that he became interested, in how many ways can he win?

The pawn, which Gerald has got left can go in two ways: one cell down or one cell to the right. in addition, it can not go to the black cells, otherwise the Gerald still loses. there are no other pawns or pieces left on the field, so that, according to the rules of giant chess Gerald moves his pawn until the game is over, and Pollard is just watching this process.

Input

The first line of the input contains three integers:H, Bytes,W, Bytes,N-The sides of the board and the number of black cells (1 ≤ upperH, Bytes,WLimit ≤ limit 105, limit 1 ≤ limitNLimit ≤ limit 2000 ).

NextNLines contain the description of black cells.I-Th of these lines contains numbersRI, Bytes,CI(1 digit ≤ DigitRILimit ≤ limitH, Memory 1 ≤ memoryCILimit ≤ limitW)-The number of the row and column ofI-Th cell.

It is guaranteed that the upper left and lower right cell are white and all cells in the description are distinct.

Output

Print a single line-the remainder of the number of ways to move Gerald's pawn from the upper left to the lower right corner modulo109 rows + rows 7.

Sample test (s) Input
3 4 22 22 3
Output
2
Input
100 100 315 1616 1599 88
Output
545732279

A rectangle, from top right to bottom left, has several steps when n points cannot pass


Question Analysis: Because h and w are relatively large, they cannot open two dimensions, but n is very small. We start with n, considering how many ways each point does not go through a bad point, first, the point is sorted in ascending order of x priority.

Dp [I] = C (xi-1 + yi-1, xi-1) This is the number of schemes from the origin point to the xi, yi, because the maximum number of XI-1 steps to the right, down to take the most Yi-1 step, so a total of xi-1 + yi-1 step, so the possible situation to directly calculate the number of combinations, in fact, xi, yi is a bad point, let's assume that it can be on a bad point. Then we need to subtract the bad point we encountered before and enumerate the points before xi and yi, then the walk between the two bad points is C (xi-xj + yi-yj, xi-xj), take dp [I]-Σ dp [j], that is, to xi, yi is removed from the previous bad point. Note that we need to add the end point to the coordinate set so that all possible bad points are subtracted from the last to the end point, you may wish to draw a picture to understand and understand. In addition, the combination number modulo should be used for this question, and the reverse yuan should be required. If the board is not good, the T20 will be caused directly, and the two boards will be replaced...

#include <cstdio>#include <algorithm>using namespace std;#define ll long longint const MOD = 1e9 + 7;ll fac[200005], dp[2005], inv[200005];int h, w, n;struct Point{int x, y;}p[2005];bool cmp(Point a, Point b){if(a.x == b.x)return a.y < b.y;return a.x < b.x;}ll get_inv(ll x){       ll res = 1, y = MOD - 2;    while(y)    {        if(y & 1)            res = (res * x) % MOD;        x = (x * x) % MOD;        y >>= 1;    }    return res;}void pre(){    fac[0] = 1;    inv[0] = 1;    for(int i = 1; i <= 200005; i++)    {        fac[i] = (fac[i - 1] * i) % MOD;        inv[i] = get_inv(fac[i]);    }}ll C(int n, int m){    return fac[n] * inv[m] % MOD * inv[n - m]% MOD;}int main(){    pre();    scanf("%d %d %d", &h, &w, &n);    for(int i = 1; i <= n; i++)    scanf("%d %d", &p[i].x, &p[i].y);    p[++ n].x = h;    p[n].y = w;    sort(p + 1, p + n + 1, cmp);    for(int i = 1; i <= n; i++)    {    dp[i] = C(p[i].x + p[i].y - 2, p[i].x - 1);    for(int j = 1; j < i; j++)    if(p[j].x <= p[i].x && p[j].y <= p[i].y)    dp[i] = (dp[i] % MOD + MOD - dp[j] * C(p[i].x - p[j].x + p[i].y - p[j].y, p[i].x - p[j].x) % MOD) % MOD;    }    printf("%lld\n", dp[n]);}


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.