Codeforces Round #313 (Div. 2) A B C 思路 枚举 数学

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 minimum unfortunate 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.

Examples
Input
5
1 2 3 4 5
Output
-1

题意:给你n个数 可多次取任意组合并求和 令不能组成的数为 不幸运的数 问你最小的不幸运的数 若不存在输出-1
题解:可以发现若n个数中存在1则可以表示任何的数 否则不能表示的最小的数为-1
 1 /*/******************************
 2 code by drizzle
 3 blog: www.cnblogs.com/hsd-/
 4 ^ ^    ^ ^
 5  O      O
 6 ******************************/
 7 #include<bits/stdc++.h>
 8 #include<map>
 9 #include<set>
10 #include<cmath>
11 #include<queue>
12 #include<bitset>
13 #include<math.h>
14 #include<vector>
15 #include<string>
16 #include<stdio.h>
17 #include<cstring>
18 #include<iostream>
19 #include<algorithm>
20 #pragma comment(linker, "/STACK:102400000,102400000")
21 using namespace std;
22 const int N=50010;
23 const int mod=1000000007;
24 const int MOD1=1000000007;
25 const int MOD2=1000000009;
26 const double EPS=0.00000001;
27 //typedef long long ll;
28 typedef __int64 ll;
29 const ll MOD=1000000007;
30 const int INF=1000000010;
31 const ll MAX=1ll<<55;
32 const double eps=1e-5;
33 const double inf=~0u>>1;
34 const double pi=acos(-1.0);
35 typedef double db;
36 typedef unsigned int uint;
37 typedef unsigned long long ull;
38 int n;
39 int flag=0;
40 int exm;
41 int main()
42 {
43     scanf("%d",&n);
44     for(int i=1;i<=n;i++)
45     {
46         scanf("%d",&exm);
47         if(exm==1)
48             flag=1;
49     }
50     if(flag)
51         cout<<"-1"<<endl;
52     else
53         cout<<"1"<<endl;
54 
55     return 0;
56 }
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 and b3 — 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).

Examples
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.

题意:给你三个矩形的边长 判断第2,3个矩形能否放入第1个矩形
题解:很恶心的列举一下 以下一种精巧的代码
 1 /*/******************************
 2 code by drizzle
 3 blog: www.cnblogs.com/hsd-/
 4 ^ ^    ^ ^
 5  O      O
 6 ******************************/
 7 #include<bits/stdc++.h>
 8 #include<map>
 9 #include<set>
10 #include<cmath>
11 #include<queue>
12 #include<bitset>
13 #include<math.h>
14 #include<vector>
15 #include<string>
16 #include<stdio.h>
17 #include<cstring>
18 #include<iostream>
19 #include<algorithm>
20 #pragma comment(linker, "/STACK:102400000,102400000")
21 using namespace std;
22 #define  A first
23 #define B second
24 const int N=50010;
25 const int mod=1000000007;
26 const int MOD1=1000000007;
27 const int MOD2=1000000009;
28 const double EPS=0.00000001;
29 //typedef long long ll;
30 typedef __int64 ll;
31 const ll MOD=1000000007;
32 const int INF=1000000010;
33 const ll MAX=1ll<<55;
34 const double eps=1e-5;
35 const double inf=~0u>>1;
36 const double pi=acos(-1.0);
37 typedef double db;
38 typedef unsigned int uint;
39 typedef unsigned long long ull;
40 int main(){
41     pair<int,int> a, b, c;
42     scanf("%d%d%d%d%d%d", &a.A, &a.B, &b.A, &b.B, &c.A, &c.B);
43     for(int k=0;k<2;k++,swap(a.A,a.B))
44         for(int i=0;i<2;i++,swap(b.A,b.B))
45             for(int j=0;j<2;j++,swap(c.A,c.B))
46                 if (a.A>=max(b.A,c.A)&&a.B>=b.B+c.B){
47                     puts("YES");
48                     return 0;
49                 }
50     puts("NO");
51     return 0;
52 }
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.

Examples
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:

题意:如图由正三角形组成的六边形 给你六条边的长度 输出三角形的个数

题解:先补全成一个大的正三角 之后剪去缺角

 1 /*/******************************
 2 code by drizzle
 3 blog: www.cnblogs.com/hsd-/
 4 ^ ^    ^ ^
 5  O      O
 6 ******************************/
 7 #include<bits/stdc++.h>
 8 #include<map>
 9 #include<set>
10 #include<cmath>
11 #include<queue>
12 #include<bitset>
13 #include<math.h>
14 #include<vector>
15 #include<string>
16 #include<stdio.h>
17 #include<cstring>
18 #include<iostream>
19 #include<algorithm>
20 #pragma comment(linker, "/STACK:102400000,102400000")
21 using namespace std;
22 const int N=50010;
23 const int mod=1000000007;
24 const int MOD1=1000000007;
25 const int MOD2=1000000009;
26 const double EPS=0.00000001;
27 //typedef long long ll;
28 typedef __int64 ll;
29 const ll MOD=1000000007;
30 const int INF=1000000010;
31 const ll MAX=1ll<<55;
32 const double eps=1e-5;
33 const double inf=~0u>>1;
34 const double pi=acos(-1.0);
35 typedef double db;
36 typedef unsigned int uint;
37 typedef unsigned long long ull;
38 int a1,a2,a3,a4,a5,a6;
39 int main()
40 {
41     scanf("%d %d %d %d %d %d",&a1,&a2,&a3,&a4,&a5,&a6);
42     int sum=a1+a2+a3;
43     int ans=sum+sum*(sum-1);
44     int ans1=a1+a1*(a1-1);
45     int ans2=(a3+a3*(a3-1));
46     int ans3=(a5+a5*(a5-1));
47     printf("%d
",ans-ans1-ans2-ans3);
48     return 0;
49 }



原文地址:https://www.cnblogs.com/hsd-/p/5918427.html