Codeforces Round #313
A. Currency System in Geraldion
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?
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.
Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print - 1.
5
1 2 3 4 5
-1
大水,没什么好说的。显然只要有1就能凑出所有数字,没有1就凑不出1,1就是那个最小的
B. Gerald is into Art
两个矩形能不能不重叠的放入第三个中。
暴力枚举一下放的方式
写的比较丑
#include <bits/stdc++.h> using namespace std; int a1, a2, a3, b1, b2, b3; bool check(){ if(max(a2, a3) <= a1 && b2 +b3<= b1) return true; if(a2 + a3 <= a1 && max(b2, b3) <= b1) return true; if(a2 + a3 <= b1 && max(b2, b3) <= a1)return true; if(max(a2, a3) <= b1 && b2 + b3 <= a1) return true; if(max(a2, b3) <= b1 && a3 + b2 <= a1) return true; if(max(a2, b3) <= a1 && a3 + b2 <= b1) return true; if(max(b2, a3) <= b1 && a2 + b3 <= a1) return true; if(max(b2, a3) <= a1 && a2 + b3 <= b1) return true; return false; } int main(){ cin >> a1 >>b1 >>a2 >>b2 >> a3 >> b3; if(a1 > b1) swap(a1, b1); if(a2 > b2) swap(a2, b2); if(a3 > b3) swap(a3, b3); printf("%s ", check() ? "YES" : "NO"); return 0; }
C. Gerald's Hexagon
给一个每个角都是120度的六边形的周长,求面积。。
一开始十分脑残企图往里面缩。。。
然而。。。。。。。。。。。。。。
酱紫,因为每个角都是120度,所以所有外角是60度,往外可以搞出一个等边三角形,删去三个小的小的三角形,就是面积了
写到后来失去思考能力了直接写了个循环求和呵呵呵==
#include <bits/stdc++.h> using namespace std; typedef __int64 ll; int a[10]; const int n = 6; int main(){ ll ans = 0; int i, t; int x, y; bool ok; for(i = 0; i < n; i++){ cin >> a[i]; } t = a[1] + a[0] + a[5]; while(t){ ans += t * 2 - 1; t--; } // cout << ans << endl; for(i = 1; i < n; i+=2){ while(a[i]){ ans -= (a[i]*2-1); a[i]--; } } cout << ans << endl; return 0; }
D. Equivalent Strings
两个字符串Equivalent 的条件是满足以下之一
1.两个字符串完全相同
2.将他们等分成等长的两部分a1 a2 b1 b2,可使得(a1Equivalent to b1 and a2 Equivalent to b2) or (a1 Equivalent to b2 and a2 Equivalent to b1)
用了一点最小表示法的思想?
直接将两个重新排个序,看是否相等。
NICE!
#include <bits/stdc++.h> using namespace std; string a, b; string gao(string s){ if(s.length() & 1) return s; string s1 = gao(s.substr(0, s.length() / 2)); string s2 = gao(s.substr(s.length()/2, s.length())); if(s1 < s2) return s1 + s2; return s2 + s1; } int main(){ cin >> a >> b; a = gao(a); b = gao(b); printf("%s ", a == b ? "YES" : "NO" ); return 0; }