Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
位运算+枚举 469ms#include<stdio.h> #include<iostream> using namespace std; int dir[16]={4383,8751,17487,34959,4593,8946,17652,35064,7953,12066,20292,36744,61713,61986,62532,63624}; int main() { // freopen("in","r",stdin); char ch; int va=0,minn=17,ans; for(int i=0;i<16;i++) { cin>>ch; if(ch=='+') va+=1<<i; } for(int i=0;i<65536;i++) { int a=va,num=0; for(int j=0;j<16;j++) { if(i&(1<<j)) { a^=dir[j]; num++; } } if(a==0) if(num<minn) { minn=num; ans=i; } } printf("%d\n",minn); for(int i=0;i<16;i++) if(ans&(1<<i)) printf("%d %d\n",i/4+1,i-i/4*4+1); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator