POJ 2965 The Pilots Brothers' refrigerator
这个题是一个枚举题。
用的是八皇后算法。
具体操作不说了。
下面是代码:
#include <stdio.h>
struct node
{int x,y;
}de[200],dr[200];
int a[17],b,w,min,cut;
void ro(int i)
{int j=4;while(i-j>=0){if(a[i-j]==0){a[i-j]=1;w--;b++;}else{a[i-j]=0;w++;b--;}j+=4;}j=4;while(i+j<16){if(a[i+j]==0){a[i+j]=1;w--;b++;}else{a[i+j]=0;w++;b--;}j+=4;}
}
void co(int i)
{int j=1;while(i+j<16&&i/4==(i+j)/4){if(a[i+j]==0){a[i+j]=1;w--;b++;}else{a[i+j]=0;w++;b--;}j++;}j=1;while(i-j>=0&&i/4==(i-j)/4){if(a[i-j]==0){a[i-j]=1;w--;b++;}else{a[i-j]=0;w++;b--;}j++;}
}
void fib(int i)
{int j,g;if(i==-1){for(j=i+1; j<16; j++){fib(j);}}else{if(cut==0&&b==0){min=cut;return ;}if(a[i]==0){a[i]=1;w--;b++;}else{a[i]=0;w++;b--;}ro(i);co(i);de[cut].x=i/4;de[cut].y=i%4;cut++;if(b==0&&min>cut){for(g=0;g<cut;g++){dr[g]=de[g];}min=cut;}else{for(j=i+1; j<16; j++){fib(j);}}if(a[i]==0){a[i]=1;w--;b++;}else{a[i]=0;w++;b--;}ro(i);co(i);cut--;}
}
int main()
{int i,j;char s[6];while(scanf("%s",s)!=EOF){b=0;w=0;min=1<<30;cut=0;for(i=0; i<4; i++){if(s[i]=='+'){a[i]=1;b++;}else if(s[i]=='-'){a[i]=0;w++;}}for(i=1; i<4; i++){scanf("%s",s);for(j=0; j<4; j++){if(s[j]=='+'){a[i*4+j]=1;b++;}else if(s[j]=='-'){a[i*4+j]=0;w++;}}}fib(-1);printf("%d\n",min);for(i=0; i<min; i++){printf("%d %d\n",dr[i].x+1,dr[i].y+1);}}return 0;
}
转载于:https://www.cnblogs.com/lin375691011/p/3996769.html
POJ 2965 The Pilots Brothers' refrigerator相关推荐
- POJ 2965.The Pilots Brothers‘ refrigerator
POJ 2965.The Pilots Brothers' refrigerator Ideas 题意:给你4*4的矩阵.每个点有两种状态,+代表关,-代表开.每个点有一个操作就是该点所在行列所有状态 ...
- ACM POJ 2965 The Pilots Brothers' refrigerator
http://poj.org/problem?id=2965 The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65 ...
- poj 2965 The Pilots Brothers' refrigerator
http://poj.org/problem?id=2965 poj 1753扩展,dfs+枚举,不过加了一个路径. The Pilots Brothers' refrigerator Time Li ...
- Poj 2965 The Pilots Brothers‘ refrigerator
The game "The Pilots Brothers: following the stripy elephant" has a quest where a player n ...
- POJ - 2965 The Pilots Brothers' refrigerator(bfs+路径输出/思维+位运算)
题目链接:点击查看 题目大意:给出一个4*4的矩阵,每个点都代表一个开关,'+'代表关,'-'代表开,每次操作可以任意改变一个开关(x,y)的状态,但代价是x行和y列的开关都要一起改变状态,题目要求将 ...
- poj 2965 The Pilots Brothers#39; refrigerator
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18040 ...
- B - The Pilots Brothers' refrigerator
B - The Pilots Brothers' refrigerator 文章目录 B - The Pilots Brothers' refrigerator 题目描述: Input: Output ...
- POJ2965 The Pilots Brothers‘ refrigerator
POJ2965 The Pilots Brothers' refrigerator 题干 Description Input Output Sample Input Sample Output 题意 ...
- The Pilots Brothers‘ refrigerator(思维)
题面:The Pilots Brothers'refrigerator 题目大意 "飞行员兄弟"这个游戏,需要玩家打开一个有着16把手的冰箱. 每个把手有且只有两种状态:打开(−- ...
最新文章
- 以金山界面库(openkui)为例思考和分析界面库的设计和实现——资源读取模块分析
- 小米手机无法连接eclipse调试案例
- 基于Cobbler实现多版本系统批量部署
- rpm卸载mysql和php_Linux系统中自带Mysql、Apache、Php卸载
- 如何做一名优秀的博士生--施一公教授
- oracle使用sql文件创建表,使用SQL*Loader创建外部表之一
- 搜索引擎(lucene)
- java怎么在哪写代码_java把这段代码不写死问题出现在哪儿
- 用户访一个APP或者网页流程示意图
- openstack常见问题解决方法
- matlab学习笔记1
- docker单机安装rocketmq双主双从
- LinkedIn领英官方API接口文档说明:授权代码流程
- Linux与windows共享文件的神器:Samba
- win11电脑加密文件夹的两种方法
- uvalive4987
- Apple Developer会员注册以及续订“支付授权失败...”问题
- java hex to ascii_在java中读取hex文件并将其转换为ascii
- fill()的使用方法
- 用智能ABC关闭程序