您的位置:首页 > 其它

Codeforces Round #231 (Div. 2) 解题报告

2014-02-21 12:21 375 查看
Problem A Counting Sticks

题意:给一个有棍子组成的加法等式现在只允许你移动一根棍子,是等式成立。

思路:比赛时候脑子卡壳直接暴力枚举,然后还有一个小地方错了,最后挂了。结束后改了过来。枚举两个加数判断是不是能从原来状态一步移到。

代码如下:

/**************************************************
* 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: