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 |
wa疯了,求组高手,求测试数据#include <iostream> #include <stdio.h> //暴力搜索,枚举所有可能,为运算 using namespace std; int flip[] = {0x111f,0x222f,0x444f,0x888f,0x11f1,0x22f2,0x44f4,0x88f8,0x1f11,0x2f22,0x4f44,0x8f88,0xf111,0xf222,0xf444,0xf888};//flip[i]表示翻第i个需要改变的那些棋子 int step = 16; int dep_status1 = 0; //记录改变了的节点 void Search(int result,int dep , int fliped,int dep_status){ //递归出全部可能 if(result == 0 ){ if(fliped < step) step = fliped; dep_status1 = dep_status; } if(dep == 16) return ; Search(result,dep+1,fliped,dep_status); Search(result ^= flip[dep] , dep+1 , fliped+1,dep_status=dep_status+(1<<dep)); return ; } int main(){ int result = 0; //根据输入初始化result for(int i = 0 ; i< 16 ;){ char temp; int x; temp = getchar(); if(temp == '+' || temp == '-'){ if(temp == '+'){ x = 1; x = x << i; result += x; } i++; } } Search(result,0,0,0); printf("%d\n",step); for(int i = 0 ; i < 16 ; i++){ int x = 1<<i; if((x&dep_status1 )!=0){ printf("%d %d\n",i/4+1,i%4+1); } } return 0; } 或者发写测试数据吧,非常感谢 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator