Codeforces Round #313 (Div. 2) (A、B、C、D)

A. Currency System in Geraldion
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 called unfortunate. 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 numbers a1, a2, ..., an (1 ≤ ai ≤ 106) — the values of the banknotes.

Output

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

Sample test(s)
input
5
1 2 3 4 5
output

-1

n种货币,数量不限,输出不能组合成的最小值 如果没有输出-1

看货币的值有没有1 如果有 任何值都能组合成 输出-1 ,否则输出1

#include <iostream>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#define inf 0x3f3f3f3f
#define N 1001
using namespace std;
int a[N];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        bool flag=true;
        for(int i=0;i<n;i++)
            {
                scanf("%d",&a[i]);
                if(a[i]==1)
                    flag=false;
            }
            if(flag)
                printf("1\n");
            else printf("-1\n");

    }
    return 0;
}





B. Gerald is into Art
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 of an a1 × b1 rectangle, the paintings have shape of a a2 × b2 and a3 × b3 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 numbers a1 and b1 — the sides of the board. Next two lines contain numbers a2, b2, a3 andb3 — the sides of the paintings. All numbers ai, bi in the input are integers and fit into the range from 1 to 1000.

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 2
1 3
2 1
output
YES
input
5 5
3 3
3 3
output
NO
input
4 2
2 3
1 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.


两幅长方形的画,问是否能放进一个长方形的木板(不能重叠),8种情况判断下就行 了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#define inf 0x3f3f3f3f
#define N 1001
using namespace std;
int a[N];
int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m))
    {
        int t;
        if(n>m)
       swap(n,m);
        int a1,a2;
        int b1,b2;
        scanf("%d%d",&a1,&a2);
        scanf("%d%d",&b1,&b2);
        if(a1>a2)
         swap(a1,a2);
        if(b1>b2)
        swap(b1,b2);
        if(a1<=n && b1<=n && (a2+b2)<=m)
        printf("YES\n");
        else if(a1<=n && b2<=n && (a2+b1)<=m)
          printf("YES\n");
        else if(a2<=n && b1<=n && (a1+b2)<=m)
          printf("YES\n");
        else if(a2<=n && b2<=n && (a1+b1)<=m)
          printf("YES\n");

       else if(a1<=m && b1<=m && (a2+b2)<=n)
        printf("YES\n");
        else if(a1<=m && b2<=m && (a2+b1)<=n)
          printf("YES\n");
        else if(a2<=m && b1<=m && (a1+b2)<=n)
          printf("YES\n");
        else if(a2<=m&& b2<=m && (a1+b1)<=n)
          printf("YES\n");
          else printf("NO\n");

    }
    return 0;
}




C. Gerald's Hexagon
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . 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 many 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 integers a1, a2, a3, a4, a5 and a6 (1 ≤ ai ≤ 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:


顺时针给出六角形的边长,问有多少个小三角形组成

长为n的等边三角形内有小三角形n*n个,六角形可以补成一个等边三角形 边长为(a+b+c),减去三个角即可

#include <iostream>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#define inf 0x3f3f3f3f
#define N 1001
using namespace std;
int main()
{
    int a,b,c,d,e,f;
    while(~scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f))
    {
        printf("%d\n",(a+b+c)*(a+b+c)-(a*a+c*c+e*e));
    }
    return 0;
}


D. Equivalent Strings
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are calledequivalent in one of the two cases:

  1. They are equal.
  2. If we split string a into two halves of the same size a1 and a2, and string b into two halves of the same size b1 and b2, then one of the following is correct:
    1. a1 is equivalent to b1, and a2 is equivalent to b2
    2. a1 is equivalent to b2, and a2 is equivalent to b1

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 from 1 to 200 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
aaba
abaa
output
YES
input
aabb
abab
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 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".

不断二分,看子串是否相等

<pre name="code" class="java">#include <iostream>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#define inf 0x3f3f3f3f
#define N 1001
using namespace std;
bool judge(string a,string b,int len)
{
    if(a==b)
        return true;
    if(len%2 || len==0)
        return false;
    len /= 2;
    string a1=a.substr(0,len);
    string a2=a.substr(len,len*2);
    string b1=b.substr(0,len);
    string b2=b.substr(len,len*2);
    if(judge(a1,b2,len) && judge(a2,b1,len))
        return true;
    if(judge(a1,b1,len) && judge(a2,b2,len))
        return true;
    return false;
}
int main()
{
    string a,b;
    while(cin>>a>>b)
    {
        int len=a.length();
        if(judge(a,b,len))
            printf("YES\n");
        else printf("NO\n");
    }

    return 0;
}

 
    


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值