代码:
#includeusing namespace std;int n[5];int a, b, c;int main() { for(int i = 0; i < 4; i ++) scanf("%d", &n[i]); sort(n, n + 4); a = n[3] - n[0]; b = n[3] - n[1]; c = n[3] - n[2]; printf("%d %d %d\n", a, b, c); return 0;}
代码:
#includeusing namespace std;const int maxn = 1010;int N;int a[maxn], vis[maxn];vector ans;int main() { scanf("%d", &N); memset(vis, 0, sizeof(vis)); for(int i = 1; i <= N; i ++) { scanf("%d", &a[i]); if(!vis[a[i]]) { ans.push_back(a[i]); vis[a[i]] = 1; } } sort(ans.begin(), ans.end()); if(ans.size() == 1) printf("0\n"); else if(ans.size() == 2) { if((ans[1] - ans[0]) % 2) printf("%d\n", ans[1] - ans[0]); else printf("%d\n", (ans[1] - ans[0]) / 2); } else if(ans.size() == 3) { if(ans[1] - ans[0] == ans[2] - ans[1]) printf("%d\n", ans[1] - ans[0]); else printf("-1\n"); } else printf("-1\n"); return 0;}
代码:
#includeusing namespace std;int day[20] = { 0, 1, 2, 0, 2, 1, 0, 0, 1, 2, 0, 2, 1, 0};int a, b, c;int main() { scanf("%d%d%d", &a, &b, &c); int ans = 0; int t = min(a / 3, min(b / 2, c / 2)); ans += t * 7; a -= (t * 3), b -= (t * 2), c -= (t * 2); int na = a, nb = b, nc = c; int maxx = 0, temp; for(int i = 0; i < 7; i ++) { int rec = 0; a = na, b = nb, c = nc; for(int j = i; j < i + 7; j ++) { if(day[j] == 0) { if(a) a --, rec ++; else { maxx = max(maxx, rec); break; } } else if(day[j] == 1) { if(b) b --, rec ++; else { maxx = max(maxx, rec); break; } } else { if(c) c --, rec ++; else { maxx = max(maxx, rec); break; } } } //printf("!%d %d %d\n", i, maxx, rec); } printf("%d\n", ans + maxx); return 0;}/*700000000 700000000 700000000*/
代码:
#includeusing namespace std;const int maxn = 2e5 + 10;int N, b, a, na, nb;int num[maxn];int main() { scanf("%d%d%d", &N, &b, &a); for(int i = 1; i <= N; i ++) scanf("%d", &num[i]); nb = b, na = a; int ans; for(int i = 1; i <= N; i ++) { if(num[i] == 1) { if(nb > 0) { if(na + 1 <= a) { na += 1; nb -= 1; } else na -= 1; } else na -= 1; } else { if(na > 0) na -= 1; else if(nb > 0) nb -= 1; } if(na == 0 && nb == 0) { ans = i; break; } //printf("%d %d\n", b, a); } printf("%d\n", min(ans, N)); return 0;}