Codeforces Round #231 (Div. 2) 解题报告
2014-02-21 12:21
375 查看
Problem A Counting Sticks
题意:给一个有棍子组成的加法等式现在只允许你移动一根棍子,是等式成立。
思路:比赛时候脑子卡壳直接暴力枚举,然后还有一个小地方错了,最后挂了。结束后改了过来。枚举两个加数判断是不是能从原来状态一步移到。
代码如下:
View Code
题意:给一个有棍子组成的加法等式现在只允许你移动一根棍子,是等式成立。
思路:比赛时候脑子卡壳直接暴力枚举,然后还有一个小地方错了,最后挂了。结束后改了过来。枚举两个加数判断是不是能从原来状态一步移到。
代码如下:
/************************************************** * Author : xiaohao Z * Blog : http://www.cnblogs.com/shu-xiaohao/ * Last modified : 2014-02-20 23:26 * Filename : Codeforce_231_2_C.cpp * Description : * ************************************************/ #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <algorithm> #include <queue> #include <stack> #include <vector> #include <set> #include <map> #define MP(a, b) make_pair(a, b) #define PB(a) push_back(a) using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<unsigned int,unsigned int> puu; typedef pair<int, double> pid; typedef pair<ll, int> pli; typedef pair<int, ll> pil; const int INF = 0x3f3f3f3f; const double eps = 1E-6; const int LEN = 1010; int n, m, Map[LEN][LEN], top[LEN], sum[LEN], cnta, cntb; int main() { // freopen("in.txt", "r", stdin); char str[10]; while(scanf("%d%d", &n, &m)!=EOF){ memset(Map, 0, sizeof Map); memset(top, 0, sizeof top); memset(sum, 0, sizeof sum); cnta = cntb = 0; for(int i=0; i<n; i++){ for(int j=0; j<m ;j++){ scanf("%s", str); if(!strcmp(str, "11")) cnta++; if(!strcmp(str, "01") || !strcmp(str, "10")) cntb++; } } int pos; for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ if(cnta==0) { pos = j; break; } Map[i][j] = 2; sum[j]+=2; top[j] ++; cnta--; } if(cnta == 0) break; } if(cntb-m>=m){ for(int j=0; j<(cntb-m)/m; j++) for(int i=0; i<m; i++){ Map[top[i]++][i] = 1; sum[i]++; } while(cntb-m>=m)cntb-=m; } for(int j=0; j<cntb; j++){ int min = INF, minpos; for(int i=0; i<m; i++){ if(top[i] < n && sum[i] < min){ min = sum[i]; minpos = i; } } Map[top[minpos]++][minpos] = 1; sum[minpos] ++; } int tag[LEN]; memset(tag, -1, sizeof tag); for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ if(Map[i][j] == 0)printf("00"); else if(Map[i][j] == 2)printf("11"); else if(Map[i][j] == 1){ if(tag[j]<0) printf("01"); else printf("10"); tag[j] = -tag[j]; } printf(" "); } printf("\n"); } } return 0; }
View Code
相关文章推荐
- CF183 div2 解题报告
- Codeforces Round #283 (Div. 2) 解题报告(A B C)
- 解题报告:Codeforces Round #364 (Div. 2) A~E
- [Updating] Codeforces Round #404 (Div. 2) 解题报告
- Codeforces Round #188 (Div. 2) A题解题报告
- Codeforces Round #407 (Div. 2)解题报告
- Codeforces Round #262 (Div. 2)解题报告
- 【解题报告】Codeforces Round #383 (Div. 2)
- codeforces_233_div2解题报告
- Codeforces Round #291 (Div. 2) 解题报告 (A B C D)
- 【解题报告】Codeforces Round #350 (Div. 2)
- codeforces Round #269(div2) C解题报告
- RCC 2014 Warmup (Div. 2) 解题报告
- codeforces Round #273(div2) D解题报告
- codeforces Round #261(div2) D解题报告
- Codeforces Round #396 (Div. 2) C题Mahmoud and a Message(dp)解题报告
- Codeforces Round #274 (Div. 2) 解题报告
- [Codeforces]Round246 div2 解题报告
- CodeForces #213 (Div. 2) A,B,C 解题报告
- Codeforces Beta Round #34 (Div. 2) A题解题报告