Poj 2965 The Pilots Brothers' refrigerator
2013-04-29 14:02
323 查看
貌似提交了很多次
估计有段时间special judge挂了...
就WAWAWA...
tle于直接搜2^16*16
firstAC于2^15*16;
next AC 于 2^12*16
搜索剪枝还是很重要的!
估计有段时间special judge挂了...
就WAWAWA...
tle于直接搜2^16*16
firstAC于2^15*16;
next AC 于 2^12*16
搜索剪枝还是很重要的!
#include<stdio.h> const int search_size=1<<12; int Cg(char x){ if(x=='+')return 1; return 0; } void next(int &x,int &y){ if(y<4){y++;return;} else {x++;y=1;return;} } int map[6][6],t[6][6]; void change(int x,int y){ int i; for(i=1;i<=4;i++)t[i][y]=1-t[i][y]; for(i=1;i<=4;i++)t[x][i]=1-t[x][i]; t[x][y]=1-t[x][y]; } int main(){ char in_map[6][6]; int i,j,k; for(i=0;i<4;i++)scanf("%s",in_map[i]); for(i=0;i<4;i++)for(j=0;j<4;j++)map[i+1][j+1]=Cg(in_map[i][j]); int res=17,mem=-1; for(k=0;k<search_size;k++){ for(i=1;i<=4;i++)for(j=1;j<=4;j++)t[i][j]=map[i][j]; int sum=0,tp=k; int x=1,y=1; for(i=1;i<=12;i++){ // if(!tp)break; int temp=tp%2;tp/=2; if(temp)change(x,y),sum++; next(x,y); } for(i=1;i<=4;i++)if(t[3][i])change(4,i),sum++; int flag=1; for(i=1;flag&&i<=4;i++)for(j=1;flag&&j<=4;j++)if(t[i][j]){flag=0;break;} if(flag){if(sum<res){res=sum;mem=k;}} } printf("%d\n",res); for(i=1;i<=4;i++)for(j=1;j<=4;j++)t[i][j]=map[i][j]; int x=1,y=1; for(i=1;i<=12;i++){ int temp=mem%2;mem/=2; if(temp)change(x,y),printf("%d %d\n",x,y); next(x,y); } for(i=1;i<=4;i++)if(t[3][i])change(4,i),printf("%d %d\n",4,i); // return main(); return 0; }
相关文章推荐
- poj2965 The Pilots Brothers' refrigerator
- POJ - 2965 - The Pilots Brothers' refrigerator (高效贪心!!)
- POJ-2965-The Pilots Brothers' refrigerator
- poj 2965 The Pilots Brothers' refrigerator(dfs 枚举 +打印路径)
- poj 2965 The Pilots Brothers' refrigerator
- POJ 2965 The Pilots Brothers' refrigerator
- poj 2965 The Pilots Brothers' refrigerator (迭代加深dfs)
- poj 2965 The Pilots Brothers' refrigerator 高斯消元法 暑假第二题
- POJ 2965:The Pilots Brothers' refrigerator:棋盘题目2
- 【POJ 2965】 The Pilots Brothers' refrigerator
- poj 2965 The Pilots Brothers' refrigerator
- poj 2965 The Pilots Brothers' refrigerator
- poj2965 The Pilots Brothers' refrigerator(直接计算或枚举Enum+dfs)
- poj 2965 The Pilots Brothers' refrigerator
- POJ 2965 The Pilots Brothers' refrigerator
- POJ 2965 The Pilots Brothers' refrigerator(反转)
- POJ 2965 The Pilots Brothers' refrigerator (想法题)
- POJ 2965-The Pilots Brothers' refrigerator
- POJ 2965-The Pilots Brothers' refrigerator(位运算+BFS+回溯路径)
- POJ:2965 The Pilots Brothers' refrigerator(二进制枚举)