A. Restoring Three Numbers
代码:
#include <bits/stdc++.h>
using namespace std; int n[];
int a, b, c; int main() {
for(int i = ; i < ; i ++)
scanf("%d", &n[i]);
sort(n, n + );
a = n[] - n[];
b = n[] - n[];
c = n[] - n[];
printf("%d %d %d\n", a, b, c);
return ;
}
B. Make Them Equal
代码:
#include <bits/stdc++.h>
using namespace std; const int maxn = ;
int N;
int a[maxn], vis[maxn];
vector<int> ans; int main() {
scanf("%d", &N);
memset(vis, , sizeof(vis));
for(int i = ; i <= N; i ++) {
scanf("%d", &a[i]);
if(!vis[a[i]]) {
ans.push_back(a[i]);
vis[a[i]] = ;
}
} sort(ans.begin(), ans.end());
if(ans.size() == ) printf("0\n");
else if(ans.size() == ) {
if((ans[] - ans[]) % )
printf("%d\n", ans[] - ans[]);
else printf("%d\n", (ans[] - ans[]) / );
} else if(ans.size() == ) {
if(ans[] - ans[] == ans[] - ans[])
printf("%d\n", ans[] - ans[]);
else printf("-1\n");
} else printf("-1\n"); return ;
}
C. Gourmet Cat
代码:
#include <bits/stdc++.h>
using namespace std; int day[] = {, , , , , , , , , , , , , };
int a, b, c; int main() {
scanf("%d%d%d", &a, &b, &c);
int ans = ;
int t = min(a / , min(b / , c / ));
ans += t * ;
a -= (t * ), b -= (t * ), c -= (t * );
int na = a, nb = b, nc = c;
int maxx = , temp;
for(int i = ; i < ; i ++) {
int rec = ;
a = na, b = nb, c = nc;
for(int j = i; j < i + ; j ++) {
if(day[j] == ) {
if(a) a --, rec ++;
else {
maxx = max(maxx, rec); break;
}
}
else if(day[j] == ) {
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 ;
} /* 700000000 700000000 700000000 */
D. Walking Robot
代码:
#include <bits/stdc++.h>
using namespace std; const int maxn = 2e5 + ;
int N, b, a, na, nb;
int num[maxn]; int main() {
scanf("%d%d%d", &N, &b, &a);
for(int i = ; i <= N; i ++)
scanf("%d", &num[i]); nb = b, na = a;
int ans;
for(int i = ; i <= N; i ++) {
if(num[i] == ) {
if(nb > ) {
if(na + <= a) {
na += ;
nb -= ;
} else na -= ;
} else na -= ;
} else {
if(na > ) na -= ;
else if(nb > ) nb -= ;
}
if(na == && nb == ) {
ans = i;
break;
} //printf("%d %d\n", b, a);
}
printf("%d\n", min(ans, N));
return ;
}