poj 2965 The Pilots Brothers' refrigerator
2014-03-26 22:26
387 查看
#include<stdio.h> struct xy{ int x,y; }; struct xy rem[16],fin[16]; int num[4][4],ans; bool check(){ int k=0; for(int i=0;i<4;i++) for(int j=0;j<4;j++) k+=num[i][j]; if(k==16) return true; return false; } void openxy(int cur){ int x=cur/4; int y=cur%4; int i,j,k; num[x][y]^=1; for(i=0;i<4;i++){ num[x][i]^=1; num[i][y]^=1; } } int enumall(int cur,int t){ if(check()&t<ans){ ans=t; for(int i=0;i<ans;i++){ fin[i].x=rem[i].x; fin[i].y=rem[i].y; } } if(cur==16) return 0; enumall(cur+1,t); openxy(cur); rem[t].x=cur/4; rem[t].y=cur%4; enumall(cur+1,t+1); openxy(cur); } int main(){ // freopen("2965.in","r",stdin); int i,j,k; char c[10]; ans=17; for(i=0;i<4;i++){ scanf("%s",c); for(j=0;j<4;j++){ if(c[j]=='-') num[i][j]=1; else num[i][j]=0; } } enumall(0,0); printf("%d\n",ans); for(i=0;i<ans;i++){ printf("%d %d\n",fin[i].x+1,fin[i].y+1); } }
#include <iostream> using namespace std; bool mark[4][4]; char s[4][4]; int main() { int i,j,k; int ci[16],cj[16]; int nas = 0; memset(mark,0,sizeof(mark)); for(i = 0;i < 4;i++) cin >> s[i]; for(i = 0;i < 4;i++) for(j = 0;j < 4;j++) { char c = s[i][j]; if(c == '+') { mark[i][j] = !mark[i][j]; for(k = 0;k < 4;k++) { mark[i][k] = !mark[i][k]; mark[k][j] = !mark[k][j]; } } } for(i = 0;i < 4;i++) for(j = 0;j < 4;j++) if(mark[i][j] == true) { ci[nas] = i + 1; cj[nas] = j + 1; nas ++; } printf("%d\n",nas); for(i = 0;i < nas;i++) { printf("%d %d\n",ci[i],cj[i]); } return 0; }
相关文章推荐
- POJ 2965 The Pilots Brothers' refrigerator
- poj2965——The Pilots Brothers' refrigerator
- POJ 2965 The Pilots Brothers' refrigerator
- poj2965_The Pilots Brothers' refrigerator(bfs)
- poj2965 The Pilots Brothers' refrigerator
- POJ 2965 (超简单代码47毫秒AC) The Pilots Brothers' refrigerator
- 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 高斯消元法 暑假第二题
- POJ 2965:The Pilots Brothers' refrigerator:棋盘题目2
- 【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(反转)