CF#787 Div3
今天不想死磕难题,因为要放假昨天一晚上都没睡着的兴奋的夜猫子本来以为今天全部的任务只是去收拾个行李,hhh想啥呢,hz会安排得让你这么闲?
一别都门三改火,天涯踏尽红尘。依然一笑做春温,
无波真古井,有节是秋筠。
惆怅孤舟连夜发,送行淡月微云。樽前不用翠眉颦,
人生如逆旅,我亦是行人。
Codeforces Round #787 Div3
A - Food for Animals
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream> #include <algorithm> #include <iomanip> #include <cmath> #include <cstring> #include <cstdio> #include <stdlib.h> #include <string.h> using namespace std; typedef long long ll; const int maxn = 5006; const ll mod = 1e9 + 7; int T, a, b, c, x, y; int read() { int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') { f = -1; } ch = getchar(); } while(ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch^48); ch = getchar(); } return x * f; } int main() { T = read(); while(T--) { a = read(); b = read(); c = read(); x = read(); y = read(); if(x <= a && y <= b) { printf("YES\n"); } else if(x >= a && y < b) { x -= a; if(c >= x) { printf("YES\n"); } else printf("NO\n"); } else if(x < a && y >= b) { y -= b; if(c >= y) { printf("YES\n"); } else printf("NO\n"); } else { x -= a; y -= b; if(c >= x+y) { printf("YES\n"); } else printf("NO\n"); } } return 0; }
B - Make It Increasing
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream> #include <algorithm> #include <iomanip> #include <cmath> #include <cstring> #include <cstdio> #include <stdlib.h> #include <string.h> using namespace std; typedef long long ll; const int maxn = 33; const ll mod = 1e9 + 7; int T, n, a[maxn], ans; int read() { int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') { f = -1; } ch = getchar(); } while(ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch^48); ch = getchar(); } return x * f; } int main() { T = read(); while(T--) { n = read(); ans = 0; bool f = 0; for(int i=1; i<=n; i++) { a[i] = read(); } for(int i=n-1; i>=1; i--) { if(a[i+1] == 0) { f = 1; break; } int k = 0; while((a[i]>>k) >= a[i+1]) { k++; } a[i] >>= k; ans += k; } if(f) { printf("-1\n"); } else { printf("%d\n", ans); } } return 0; }
C - Detective Task
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream> #include <algorithm> #include <iomanip> #include <cmath> #include <cstring> #include <cstdio> #include <stdlib.h> #include <string.h> using namespace std; typedef long long ll; const int maxn = 2e5 + 3; const ll mod = 1e9 + 7; int T, n, l, r; char s[maxn]; int read() { int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') { f = -1; } ch = getchar(); } while(ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch^48); ch = getchar(); } return x * f; } int main() { T = read(); while(T--) { scanf("%s", s+1); n = strlen(s+1); l = 1, r = n; for(int i=1; i<=n; i++) { if(s[i] == '1') l = max(l, i); else if(s[i] == '0') r = min(r, i); } //printf("r = %d l = %d\n", r, l); printf("%d\n", (r-l+1)); } return 0; }
时光花火,水月星辰