GYM
来源:互联网 发布:伊甸园 本站域名是什么 编辑:程序博客网 时间:2024/06/07 16:07
题意:给你一个特殊的遥控器,问你换台所需按按键的最小次数。
解题思路:台数很少,爆搜即可。
#include<iostream>#include<bitset>#include<queue>using namespace std;typedef long long int ll;const ll INF=(1LL<<62);bool ok[15];//记录遥控器按钮状态bool vis[1000];//记录当前台是否被访问过struct point{ int num; int step; point(int a=0,int b=0){ num=a; step=b; }};int ans=10000;void bfs(int s,int e){ queue<point> que; que.push(point(s,0)); vis[s]=1; while(!que.empty()){ point tp=que.front(); que.pop(); vis[tp.num]=1; vis[e]=0; if(tp.num==e){ ans=min(tp.step,ans); continue; } //直接按单个按钮 for(int i=1;i<=10;i++) if(ok[i]&&vis[i%10]==0) que.push(point(i%10,tp.step+1)); //下一台 int temp=0; if(tp.num+1==100) temp=0; else temp=tp.num+1; if(ok[11]&&vis[temp]==0) que.push(point(temp,tp.step+1)); //上一台 temp=0; if(tp.num-1==-1) temp=99; else temp=tp.num-1; if(ok[12]&&vis[temp]==0) que.push(point(temp,tp.step+1)); //双位数 if(ok[13]){ for(int i=1;i<=10;i++) for(int j=1;j<=10;j++){ int x=i%10; int y=j%10; if(ok[i]&&ok[j]&&vis[x*10+y]==0) que.push(point(x*10+y,tp.step+3)); } } } if(ans==10000) ans= -1;}int main(){ //这样输入方便搜索 for(int i=1;i<=3;i++) cin>>ok[i]; cin>>ok[11]; for(int i=4;i<=6;i++) cin>>ok[i]; cin>>ok[12]; for(int i=7;i<=9;i++) cin>>ok[i]; cin>>ok[13]; cin>>ok[10]; int X,Y; cin>>X>>Y; bfs(X,Y); cout<<ans<<endl; return 0;}
阅读全文
0 0
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- qt5编译boost
- mysql索引
- mysql中的length函数相关
- ABBYY FineReader Pro for Mac完整功能汇总(二)
- android布局之RelativeLayout
- GYM
- win32控制台停留--ctrl+f5
- Swift Core Data
- Android 线程管理之 CountDownLatch(闭锁)
- 使用Maven构建项目,spring整合mybatis发生错误:Mapped Statements collection does not contain value for
- Spring Bean InitializingBean和DisposableBean实例区别
- 原码, 反码, 补码 详解
- 多行多列RadioGroup
- git 关联远程仓库的问题