Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

100A留个纪念

Posted by Akrusher at 2016-04-05 22:58:47 on Problem 1222 and last updated at 2016-04-05 22:59:36
/*
* Created:     2016年04月05日 22时28分26秒 星期二
* Author:      Akrusher
*
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define in(n) scanf("%d",&(n))
#define in2(x1,x2) scanf("%d%d",&(x1),&(x2))
#define in3(x1,x2,x3) scanf("%d%d%d",&(x1),&(x2),&(x3))
#define inll(n) scanf("%I64d",&(n))
#define inll2(x1,x2) scanf("%I64d%I64d",&(x1),&(x2))
#define inlld(n) scanf("%lld",&(n))
#define inlld2(x1,x2) scanf("%lld%lld",&(x1),&(x2))
#define inf(n) scanf("%f",&(n))
#define inf2(x1,x2) scanf("%f%f",&(x1),&(x2))
#define inlf(n) scanf("%lf",&(n))
#define inlf2(x1,x2) scanf("%lf%lf",&(x1),&(x2))
#define inc(str) scanf("%c",&(str))
#define ins(str) scanf("%s",(str))
#define out(x) printf("%d\n",(x))
#define out2(x1,x2) printf("%d %d\n",(x1),(x2))
#define outf(x) printf("%f\n",(x))
#define outlf(x) printf("%lf\n",(x))
#define outlf2(x1,x2) printf("%lf %lf\n",(x1),(x2));
#define outll(x) printf("%I64d\n",(x))
#define outlld(x) printf("%lld\n",(x))
#define outc(str) printf("%c\n",(str))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define mem(X,Y) memset(X,Y,sizeof(X));
typedef vector<int> vec;
typedef long long ll;
typedef pair<int,int> P;
const int dx[5]={-1,0,0,0,1},dy[5]={0,-1,0,1,0};
const int INF=0x3f3f3f3f;
const ll mod=1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
const bool AC=true;

const int M=5;
const int N=6;
int tile[5][6];
int opt[5][6];
int flip[5][6];
int k;
int get(int x,int y){
	int c=tile[x][y];
	rep(i,0,5){
		int nx=x+dx[i],ny=y+dy[i];
		if(nx>=0&&ny>=0&&nx<M&&ny<N){
			c+=flip[nx][ny];	
		}
	}
  return c%2;
 }
int calc(){
 	rep(i,1,M){
 		rep(j,0,N){
 			if(get(i-1,j)) flip[i][j]=1;
 			}
 		}
 	rep(j,0,N){
 		if(get(M-1,j)){
 			return -1;
 		}
 	}
 	int res=0;
 	rep(i,0,M) 
 		rep(j,0,N)
 			if(flip[i][j]) res++;
 	return res;
}
void solve(){
	int res=-1;
	rep(i,0,1<<N){
		mem(flip,0);
		rep(j,0,N){
			flip[0][N-j-1]=(i>>j)&1;
		}
	int num=calc();
	if(num>=0&&(res<0||res>num)){ //此处可能为0
		res=num;
		memcpy(opt,flip,sizeof(flip));
	}
	}
	printf("PUZZLE #%d\n",k);
	rep(i,0,M){
		rep(j,0,N){
			printf("%d ",opt[i][j]);
			}
		printf("\n");
		}
}
int main()
{
	int t;
	in(t);
	k=0;
	while(t--){
		k++;
		rep(i,0,M)
			rep(j,0,N){
			in(tile[i][j]);
			}
		solve();
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator