http://codeforces.com/contest/1472
A. Cards for Friends
将最多可以剪裁的块数算出来,大于需要的块数就输出YES,小于需要的块数就输出NO
为了节省时间,一边计算一边判断当前裁剪的块数够不够需要块数,如果已经够了直接break掉
ll n;
cin >> n;
ll h, w, t;
for(ll i = 0; i < n; i ++) {
ll ans = 1;
cin >> h >> w >> t;
while(w % 2 == 0) {
ans *= 2;
w /= 2;
if(ans >= t) {
break;
}
}
while(h % 2 == 0) {
ans *= 2;
h /= 2;
if(ans >= t) {
break;
}
}
if(ans >= t) {
cout << "YES\n";
}
else {
cout << "NO\n";
}
}
B. Fair Division
有一把糖,1g的和2g的,俩小孩平均分,糖不能切,给出每个糖的重量,问能不能平分
总克数是奇数,一定不能平分;
总克数是偶数的话,如果存在1g的糖一定能平分(一定是偶数个),只存在2g的糖的话一定被4整除(每人得到2g的倍数)
换个角度,如果能平分,只有1g那种的,两人各给1个;只有2g那种的,一人一个2g的,总克数一定能被4整除;既有1g的也有2g的,总克数一定能被2整除
void solve() {
ll n;
cin >> n;
ll all = 0;
bool f = 0;
while(n --) {
ll t;
cin >> t;
all += t;
if(t == 1) {
f = 1;
}
}
if(all & 1) {
cout << "NO\n";
}
else if(f || all % 4 == 0) {
cout << "YES\n";
}
else {
cout << "NO\n";
}
return;
}
C. Long Jumps
简单DP
int T; cin >> T;
while(T --) {
int n;
cin >> n;
for(int i = 1; i <= n; i ++) {
cin >> a[i];
}
int ans = 0;
for(int i = n; i >= 1; i --) {
if(a[i] + i > n) {
dp[i] = a[i];
}
else {
dp[i] = max(a[i], dp[i + a[i]] + a[i]);
}
ans = max(ans, dp[i]);
}
cout << ans << endl;
}
D. Even-Odd Game
duplicate 重复的
tie 平局
int T; cin >> T;
while(T --) {
int n;
cin >> n;
int B = 0, A = 0;
for(int i = 1; i <= n; i ++) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
lli s1 = 0, s2 = 0;
for(int i = n; i >= 1; i --) {
if((n - i) % 2 == 0 && a[i] % 2 == 0) s1 += a[i];
if((n - i) & 1 && a[i] & 1) s2 += a[i];
}
if(s1 == s2) cout << "Tie\n";
else if(s1 < s2) cout << "Bob\n";
else cout << "Alice\n";
}
E. Correct Placement
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
struct st {
int w, h, id;
} a[N];
int t, n, i, j, k, mmin, ans[N];
bool cmp(st p, st q) { return (p.w == q.w) ? p.h < q.h : p.w < q.w; }
int main() {
std::ios::sync_with_stdio(false);
cin >> t;
while (t--) {
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a[i].w >> a[i].h;
if (a[i].w > a[i].h)
swap(a[i].w, a[i].h);
a[i].id = i;
ans[i] = -1;
}
sort(a + 1, a + n + 1, cmp);
mmin = a[0].h = 1e9 + 7;
j = 1;
k = 0;
for (i = 2; i <= n; i++) {
while (a[j].w < a[i].w) {
if (a[j].h < mmin) {
mmin = a[j].h;
k = j;
}
j++;
}
if (a[k].h < a[i].h)
ans[a[i].id] = a[k].id;
}
for (i = 1; i <= n - 1; i++)
cout << ans[i] << ' ';
cout << ans[n] << endl;
}
return 0;
}
F. New Year’s Puzzle
学习,制作pair两种办法:
sz.push_back(make_pair(a, b));
sz.push_back({b, a});