Educational Codeforces Round 10
DUANG: http://codeforces.com/contest/652
A
爬上爬下瞎搞
想复杂了不怎么敢交结果一发A了
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int main(){ 5 //while(true){ 6 int h1, h2, a, b; 7 scanf("%d %d %d %d", &h1, &h2, &a, &b); 8 h1 += 8 * a; 9 int ans = -1; 10 bool flag = false; 11 if(h1 >= h2) ans = 0; 12 else{ 13 if(b < a){ 14 ans = 0; 15 while(h1 < h2){ 16 ++ans; 17 h1 -= 12*b; 18 h1 += 12*a; 19 } 20 } 21 } 22 printf("%d\n", ans); 23 //} 24 return 0; 25 }
B
根据题意要把给定数组排成一小一大交替的数组
排序后要小的前面拿要大的后面拿
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 const int MAXN = 1111; 5 int num[MAXN]; 6 int ans[MAXN]; 7 8 int main(){ 9 int n; 10 scanf("%d", &n); 11 for(int i = 0; i < n; ++i) scanf("%d", &num[i]); 12 sort(num, num+n); 13 int l = 0, r = n-1, x = 0; 14 for(int i = 0; i < n; ++i) 15 if(i & 1) ans[x++] = num[r--]; 16 else ans[x++] = num[l++]; 17 for(int i = 0; i < n; ++i) 18 printf("%d%c", ans[i], " \n"[i==n-1]); 19 return 0; 20 }
C
给一个排列和m对数,求有多少个区间不包含m对数中任意一对
参考了大神的题解: http://www.cnblogs.com/qscqesze/p/5330279.html
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 typedef long long ll; 5 const int MAXN = 333333; 6 int num[MAXN]; 7 int pos[MAXN]; 8 int lex[MAXN]; 9 10 int main(){ 11 int n, m; 12 scanf("%d %d", &n, &m); 13 for(int i = 1; i <= n; ++i){ 14 scanf("%d", &num[i]); 15 pos[num[i]] = i; 16 } 17 for(int i = 1; i <= m; ++i){ 18 int x, y; 19 scanf("%d %d", &x, &y); 20 int a = max(pos[x], pos[y]), b = min(pos[x], pos[y]); 21 lex[a] = max(lex[a], b); 22 } 23 ll ans = 0; 24 int k = 0; 25 for(int i = 1; i <= n; ++i){ 26 k = max(lex[i], k); 27 ans += i - k; 28 } 29 printf("%I64d\n", ans); 30 // for(int i = 1; i <= n; ++i) printf("%d%c", i, " \n"[i==n]); 31 // for(int i = 1; i <= n; ++i) printf("%d%c", num[i], " \n"[i==n]); 32 // for(int i = 1; i <= n; ++i) printf("%d%c", pos[i], " \n"[i==n]); 33 // for(int i = 1; i <= n; ++i) printf("%d%c", lex[i], " \n"[i==n]); 34 return 0; 35 }
D
离散化+树状数组?(待补)
EF不会...........