POJ 1166 The Clocks(暴力搜索)
来源:互联网 发布:sql isequal 编辑:程序博客网 时间:2024/05/17 23:20
ACM选修课布置的第二题,第一题貌似是贪心+枚举,看着题意挺纠结的,而且没看懂题意就先放下了。这题之前在USACO上貌似做过类似的题,当时写的很恶心,这次写这题的时候思路很轻松,写起来也比较简单。这题也没多想,直接枚举没种操作的次数,因为执行四次同样的操作和没执行过的状态是一样的,而且每种操作的执行顺序和最终结果无关,所以每种操作的状态最多就有4种,总共就种操作,最多就4^9种情况,暴力枚举无压力也就没写bfs,感觉bfs要快很多,算了,不在水题上纠结了……
#include <iostream>#include <string.h>#include <cstdio>#include <cmath>using namespace std;int clock[10],ans;int temp[10],step[10];int turn[9][9]={ {1,1,0,1,1,0,0,0,0}, {1,1,1,0,0,0,0,0,0}, {0,1,1,0,1,1,0,0,0}, {1,0,0,1,0,0,1,0,0}, {0,1,0,1,1,1,0,1,0}, {0,0,1,0,0,1,0,0,1}, {0,0,0,1,1,0,1,1,0}, {0,0,0,0,0,0,1,1,1}, {0,0,0,0,1,1,0,1,1}};void dfs(int value,int deep){ if(deep==9) { bool ok=true; for(int i=0;i<9;i++) { if(clock[i]%4!=0) { ok=false; break; } } if(ok) { if(ans>value) { ans=value; memcpy(step,temp,sizeof(step)); } } return; } for(int i=0;i<4;i++) { temp[deep]=i; for(int j=0;j<9;j++) clock[j]=(clock[j]+turn[deep][j]*i)%4; dfs(i+1,deep+1); for(int j=0;j<9;j++) clock[j]=(clock[j]-turn[deep][j]*i)%4; }}int main(){ for(int i=0; i<9; i++) { scanf("%d",&clock[i]); } ans=100000; dfs(0,0); bool ok=true; for(int i=0;i<9;i++) { while(step[i]--) { if(ok) { printf("%d",i+1); ok=false; } else printf(" %d",i+1); } } printf("\n");}
- POJ 1166 The Clocks(暴力搜索)
- poj 1166 The Clocks 暴力搜索
- The Clocks(暴力搜索)
- poj 1166 The Clocks 暴力枚举
- poj 1166 The Clocks (暴力|| dfs)
- POJ 1166 The Clocks(搜索枚举)
- POJ 1166 The clocks
- POJ 1166 The Clocks
- POJ 1166 The Clocks
- POJ 1166 The Clocks
- poj 1166 The Clocks
- POJ 1166 The Clocks
- poj 1166 The Clocks
- poj 1166 The Clocks
- poj 1166 The Clocks
- poj The Clocks 1166
- POJ 1166 The Clocks
- POJ 1166:The Clocks
- 软件开发高手须掌握的4大SQL精髓语句(三)
- Unity3D的Android游戏添加google广告的插件及使用方法
- WordPress的几款代码高亮插件比较
- Active object Design Pattern
- Zigbee开发板学习笔记(二)
- POJ 1166 The Clocks(暴力搜索)
- SAP FI/CO常用表及表关系
- linux的最基本操作
- Android游戏进赚钱时刻 年内现月收入过千万游戏
- JIRA从HSQL切换到MySQL
- Java虚拟机学习 - 对象访问
- 《Windows程序设计》读书笔记
- Trie树
- 最赚钱的五大软件高薪职业:不容错过