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 |
这么简单的一道暴搜花了一上午,47ms,贴代码!!!#include <iostream> #include <math.h> using namespace std; void search(int cur,int dep); bool find=false; int flip[16]={51200,58368,29184,12544,35968,20032,10016,4880,2248,1252,626,305,140,77,39,19}; int count=0; int finalans=16; int main() { char c ; int value=0; for(int i=0;i<16;) { c=getchar(); if(c=='b') { value+=pow(2.0,15-i); i++; } else if(c=='w') { i++; } else continue; } search(value,0); if(!find) cout<<"Impossible"<<endl; else cout<<finalans<<endl; system("pause"); return 0; } void search(int cur,int dep) { if(cur==65535||cur==0) { find=true; if(count<finalans) finalans=count; } if(dep==16) return ; int temp=cur; cur=cur^flip[dep]; count++; search(cur,dep+1); count--; search(temp,dep+1); } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator