Codeforces Round #283 (Div. 2) ABCDE
ABC都比较水。贴个代码。
A
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 #include <cmath> 6 #include <queue> 7 8 using namespace std; 9 10 #define LL long long 11 #define eps 1e-8 12 #define inf 0x3f3f3f3f 13 #define mnx 1010 14 15 int a[mnx]; 16 int main(){ 17 int n; 18 scanf( "%d", &n ); 19 for( int i = 0; i < n; ++i ) 20 scanf( "%d", &a[i] ); 21 int ans = inf; 22 for( int i = 2; i < n; ++i ){ 23 int tmp = a[i] - a[i-2]; 24 for( int j = 1; j < n; ++j ){ 25 if( j != i ) 26 tmp = max( tmp, a[j] - a[j-1] ); 27 } 28 ans = min( ans, tmp ); 29 } 30 cout << ans << endl; 31 return 0; 32 }
B
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 #include <cmath> 6 #include <queue> 7 8 using namespace std; 9 10 #define LL long long 11 #define eps 1e-8 12 #define inf 0x3f3f3f3f 13 #define mnx 1010 14 15 char s[mnx], ans[mnx], b[mnx]; 16 int main(){ 17 int n; 18 scanf( "%d", &n ); 19 scanf( "%s", s ); 20 strcpy( ans, s ); 21 for( int i = 0; i < 10; ++i ){ 22 for( int j = 0; j < n; ++j ){ 23 for( int k = 0; k < n; ++k ){ 24 b[k] = s[(k+j)%n]; 25 } 26 if( strcmp( ans, b ) == 1 ) 27 strcpy( ans, b ); 28 } 29 for( int j = 0; j < n; ++j ){ 30 if( s[j] == '9' ) s[j] = '0'; 31 else s[j]++; 32 } 33 } 34 for( int i = 0; i < n; ++i ) 35 printf( "%c", ans[i] ); 36 puts( "" ); 37 return 0; 38 }
C。不断的贪心就好了。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 #include <cmath> 6 #include <queue> 7 8 using namespace std; 9 10 #define LL long long 11 #define eps 1e-8 12 #define inf 0x3f3f3f3f 13 #define mnx 110 14 15 char g[mnx][mnx]; 16 bool ok[mnx]; 17 int n, m, ans; 18 void cal( int a ){ 19 for( int i = 0; i < m; ++i ){ 20 if( ok[i] ) continue; 21 if( g[a][i] > g[a-1][i] ) return; 22 if( g[a][i] < g[a-1][i] ){ 23 ok[i] = 1; ans++; 24 } 25 } 26 return; 27 } 28 int main(){ 29 scanf( "%d %d", &n, &m ); 30 getchar(); 31 for( int i = 0; i < n; ++i ) 32 gets( g[i] ); 33 ans = 0; 34 for( int j = 1; j < 100; ++j ){ 35 for( int i = 1; i < n; ++i ) 36 cal( i ); 37 } 38 printf( "%d\n", ans ); 39 return 0; 40 }
D题有点坑。给你n个数,给出每轮的胜负情况(第一个人赢或者第二个人赢),叫你输出所有可能的s 和 t的方案。
x[i]表示第一个人赢第i次时是哪一轮,xw[i]表示第一个人第i轮的时候赢了多少次。y[i], yw[i]则表示第二个人的。
枚举赢一局需要赢多少次,算出两个人赢的局数,判断一下是不是符合条件。是的话就加入答案里面。排个序输出就好了。。
有点坑,之前一直把
![](https://images0.cnblogs.com/blog2015/652481/201505/232325357811251.png)
写成了 if(w1 > w2 && x[sx] == n) 和 if(w2 > w1 && y[sy] == n)跪了好多发。都找不出错,最后从cf上搞了一组数据下来才发现这里挫了。
改了之后还错了,因为数组开的不够大,x[sx+i] 跟 y[sy+i]那里有可能到20w。。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include <cstring> 3 #include <string> 4 #include <cstdio> 5 #include <algorithm> 6 #include <cmath> 7 #include <cstdlib> 8 #include <set> 9 #include <queue> 10 #include <vector> 11 using namespace std; 12 13 #define LL long long 14 #define N 205000 15 #define M 2020 16 #define eps 1e-10 17 #define inf 0x3f3f3f3f 18 #define MP make_pair 19 #define Pi acos(-1.0) 20 #define mod 1000000007 21 #pragma comment(linker, "/STACK:1024000000,1024000000") 22 23 struct node{ 24 int s, t; 25 node(int s = 0, int t = 0) : s(s), t(t) {} 26 bool operator < (const node &b) const{ 27 return s < b.s || (s == b.s && t < b.t); 28 } 29 }; 30 node ans[N]; 31 int x[N], y[N], xw[N], yw[N]; 32 int main(){ 33 int n, all = 0; 34 scanf("%d", &n); 35 memset(x, -1, sizeof x); 36 memset(y, -1, sizeof y); 37 int w1 = 0, w2 = 0; 38 for(int i = 1; i <= n; ++i){ 39 int a; 40 scanf("%d", &a); 41 if(a == 1) 42 x[++w1] = i, xw[i] = w1, yw[i] = yw[i-1]; 43 else 44 y[++w2] = i, yw[i] = w2, xw[i] = xw[i-1]; 45 } 46 for(int i = 1; i <= max(w1, w2); ++i){ 47 int sx = 0, sy = 0, win1 = 0, win2 = 0; 48 while(1){ 49 int nx = x[sx+i], ny = y[sy+i]; 50 if(nx == -1 && ny == -1) break; 51 if(nx == -1 && ny != -1){ 52 win2++; 53 sx = xw[ny], sy = yw[ny]; 54 } 55 else if(nx != -1 && ny == -1){ 56 win1++; 57 sx = xw[nx], sy = yw[nx]; 58 } 59 else{ 60 if(nx < ny) 61 win1++, sx = xw[nx], sy = yw[nx]; 62 else win2++, sx = xw[ny], sy = yw[ny]; 63 } 64 } 65 if(win1 > win2 && x[sx] == n) 66 ans[all++] = node(win1, i); 67 if(win2 > win1 && y[sy] == n) 68 ans[all++] = node(win2, i); 69 } 70 printf("%d\n", all); 71 sort(ans, ans + all); 72 for(int i = 0; i < all; ++i) 73 printf("%d %d\n", ans[i].s, ans[i].t); 74 return 0; 75 }
E题。这样的类型做过好多次了,贪心排序,然后用stl来搞。这次也不例外。把每个节目按照b由小到大排,把每个人按照d由小到大排,然后扫一遍,给每个人选适合的节目。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include <cstring> 3 #include <string> 4 #include <cstdio> 5 #include <algorithm> 6 #include <cmath> 7 #include <cstdlib> 8 #include <set> 9 #include <queue> 10 #include <vector> 11 using namespace std; 12 13 #define LL long long 14 #define N 100020 15 #define M 2020 16 #define eps 1e-10 17 #define inf 0x3f3f3f3f 18 #define MP make_pair 19 #define Pi acos(-1.0) 20 #define mod 1000000007 21 #pragma comment(linker, "/STACK:1024000000,1024000000") 22 23 struct play{ 24 int u, v, k, id; 25 bool operator < (const play &b) const{ 26 return v < b.v || (v == b.v && u < b.u); 27 } 28 }; 29 play p[N], q[N]; 30 set<pair<int, int> > s; 31 set<pair<int, int> >::iterator it, itt; 32 int ans[N]; 33 int main(){ 34 int n, m; 35 scanf("%d", &n); 36 for(int i = 0; i < n; ++i) 37 scanf("%d%d", &p[i].u, &p[i].v), p[i].k = i + 1; 38 sort(p, p + n); 39 scanf("%d", &m); 40 for(int i = 0; i < m; ++i) 41 scanf("%d%d%d", &q[i].u, &q[i].v, &q[i].k), q[i].id = i + 1; 42 sort(q, q + m); 43 int j = 0; 44 for(int i = 0; i < m; ++i){ 45 int k = q[i].k; 46 while(p[j].v <= q[i].v && j < n){ 47 s.insert(MP(p[j].u, p[j].k)); 48 j++; 49 } 50 it = s.lower_bound(MP(q[i].u, -1)); 51 itt = it; 52 for(; it != s.end() && k > 0; ++it, k--) 53 ans[(*it).second] = q[i].id; 54 s.erase(itt, it); 55 } 56 if(j == n && s.size() == 0){ 57 puts("YES"); 58 for(int i = 1; i <= n; ++i) 59 printf("%d%c", ans[i], i == n ? '\n' : ' '); 60 } 61 else puts("NO"); 62 return 0; 63 }