标签:
A - Exam 构造
1 #include <cstdio> 2 3 int ans[5000 + 5]; 4 5 int main() { 6 int n, cnt = 1; 7 scanf("%d", &n); 8 for (int i = 1; i <= n; i++) { 9 if (i&1) ans[i] = cnt; 10 else { 11 ans[i] = n+1-cnt; 12 cnt++; 13 } 14 } 15 ans[0] = ans[n]; 16 if (n == 1 || n == 2) { 17 printf("1\n1\n"); 18 return 0; 19 } 20 if (n == 3) { 21 printf("2\n1 3\n"); 22 return 0; 23 } 24 printf("%d\n", n); 25 for (int i = 0; i < n; i++) 26 printf("%d ", ans[i]); 27 return 0; 28 }
B - Covered Path 想法题
1 #include <cstdio> 2 3 inline int min(int a, int b) { 4 return a < b ? a : b; 5 } 6 7 int main() { 8 int v1, v2, t, d; 9 scanf("%d%d%d%d", &v1, &v2, &t, &d); 10 int ans = 0; 11 for (int i = 0; i < t; i++) 12 ans += min(v1+i*d, v2+(t-i-1)*d); 13 printf("%d\n", ans); 14 return 0; 15 }
C - Polycarpus‘ Dice 求上下界
1 #include <cstdio> 2 3 const int N = 100000*2 + 5; 4 typedef long long ll; 5 ll ans[N], num[N], suf[N], pre[N]; 6 7 int main() { 8 int n; 9 ll s; 10 scanf("%d%lld", &n, &s); 11 for (int i = 1; i <= n; i++) 12 scanf("%lld", num+i); 13 for (int i = 1; i <= n; i++) 14 pre[i] = pre[i-1] + num[i]; 15 for (int i = n; i >= 1; i--) 16 suf[i] = suf[i+1] + num[i]; 17 ll can_min, can_max; 18 for (int i = 1; i <= n; i++) { 19 can_min = s - pre[i-1] - suf[i+1]; 20 if (can_min < 1) can_min = 1; 21 can_max = s - n + 1; 22 if (can_max > num[i]) can_max = num[i]; 23 ans[i] = num[i] - (can_max - can_min + 1); 24 } 25 for (int i = 1; i <= n; i++) 26 printf("%lld ", ans[i]); 27 return 0; 28 }
Codeforces Round #298 (Div. 2)
标签:
原文地址:http://www.cnblogs.com/chbeater/p/4423539.html