这个题是一个枚举题。

用的是八皇后算法。

具体操作不说了。

下面是代码:


#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相关推荐

  1. POJ 2965.The Pilots Brothers‘ refrigerator

    POJ 2965.The Pilots Brothers' refrigerator Ideas 题意:给你4*4的矩阵.每个点有两种状态,+代表关,-代表开.每个点有一个操作就是该点所在行列所有状态 ...

  2. ACM POJ 2965 The Pilots Brothers' refrigerator

    http://poj.org/problem?id=2965 The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65 ...

  3. poj 2965 The Pilots Brothers' refrigerator

    http://poj.org/problem?id=2965 poj 1753扩展,dfs+枚举,不过加了一个路径. The Pilots Brothers' refrigerator Time Li ...

  4. Poj 2965 The Pilots Brothers‘ refrigerator

    The game "The Pilots Brothers: following the stripy elephant" has a quest where a player n ...

  5. POJ - 2965 The Pilots Brothers' refrigerator(bfs+路径输出/思维+位运算)

    题目链接:点击查看 题目大意:给出一个4*4的矩阵,每个点都代表一个开关,'+'代表关,'-'代表开,每次操作可以任意改变一个开关(x,y)的状态,但代价是x行和y列的开关都要一起改变状态,题目要求将 ...

  6. poj 2965 The Pilots Brothers#39; refrigerator

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18040 ...

  7. B - The Pilots Brothers' refrigerator

    B - The Pilots Brothers' refrigerator 文章目录 B - The Pilots Brothers' refrigerator 题目描述: Input: Output ...

  8. POJ2965 The Pilots Brothers‘ refrigerator

    POJ2965 The Pilots Brothers' refrigerator 题干 Description Input Output Sample Input Sample Output 题意 ...

  9. The Pilots Brothers‘ refrigerator(思维)

    题面:The Pilots Brothers'refrigerator 题目大意 "飞行员兄弟"这个游戏,需要玩家打开一个有着16把手的冰箱. 每个把手有且只有两种状态:打开(−- ...

最新文章

  1. 以金山界面库(openkui)为例思考和分析界面库的设计和实现——资源读取模块分析
  2. 小米手机无法连接eclipse调试案例
  3. 基于Cobbler实现多版本系统批量部署
  4. rpm卸载mysql和php_Linux系统中自带Mysql、Apache、Php卸载
  5. 如何做一名优秀的博士生--施一公教授
  6. oracle使用sql文件创建表,使用SQL*Loader创建外部表之一
  7. 搜索引擎(lucene)
  8. java怎么在哪写代码_java把这段代码不写死问题出现在哪儿
  9. 用户访一个APP或者网页流程示意图
  10. openstack常见问题解决方法
  11. matlab学习笔记1
  12. docker单机安装rocketmq双主双从
  13. LinkedIn领英官方API接口文档说明:授权代码流程
  14. Linux与windows共享文件的神器:Samba
  15. win11电脑加密文件夹的两种方法
  16. uvalive4987
  17. Apple Developer会员注册以及续订“支付授权失败...”问题
  18. java hex to ascii_在java中读取hex文件并将其转换为ascii
  19. fill()的使用方法
  20. 用智能ABC关闭程序

热门文章

  1. 12操作系统面临的安全威胁安全脆弱性基本概念
  2. 运行 Shell 脚本有两种方法:
  3. rt5350 h264 sn9c291 的RTSP 延时测试
  4. mysql odbc连接 mdb_java中采用ODBC方式连接Access数据库
  5. java计算机毕业设计家庭理财管理系统源码+数据库+系统+lw文档+mybatis+运行部署
  6. 宇宙有新惊喜了吗?十亿光年外存在巨大的反物质喷泉?
  7. 6、基带信号的发送和接收
  8. CSDN官方力推的《用户社区》,值得你来逛逛
  9. 裸辞接单第一个月的收入
  10. 变电站气象站(电力微气象监测站)是什么?