hdu 1104 Remainder 队列
2015-06-07 14:08
429 查看
[code]#include <set> #include <map> #include <queue> #include <stack> #include <math.h> #include <time.h> #include <vector> #include <string> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream> #include <algorithm> using namespace std; struct node { int n; int step; string road; }p1,p2; int n,m,k,km,vis[1000000+5]; void bfs() { memset(vis,0,sizeof(vis)); queue<node>q; p1.n=n; p1.step=0; p1.road=""; vis[(p1.n%k+k)%k]=1; q.push(p1); while(!q.empty()) { p1=q.front(); q.pop(); if(((n+1)%k+k)%k==((p1.n)%k+k)%k) { printf("%d\n",p1.step); cout<<p1.road<<endl; return ; } for(int i=0;i<4;i++) { p2=p1; p2.step++; if(i==0) { p2.n=(p2.n+m)%km; p2.road+='+'; } else if(i==1) { p2.n=(p2.n-m)%km; p2.road+='-'; } else if(i==2) { p2.n=(p2.n*m)%km; p2.road+='*'; } else if(i==3) { p2.n=(p2.n%m+m)%m%km; p2.road+='%'; } if(!vis[(p2.n%k+k)%k]) { vis[(p2.n%k+k)%k]=1; q.push(p2); } } } printf("0\n"); } int main() { while(~scanf("%d%d%d",&n,&k,&m)&&n&&m&&k) { km=k*m; bfs(); } return 0; }
相关文章推荐
- hdu 1104 Remainder 队列
- xiugaicrontab默认编辑器
- HDU 5240 E - Exam(2015 ACM-ICPC China Shanghai Metropolitan Programming Contest)
- BZOJ 1664: [Usaco2006 Open]County Fair Events 参加节日庆祝( dp )
- poj 1273 Drainage Ditches 【最大流入门 dinic算法】
- NOI2011阿狸的打字机(fail树+DFS序)
- 【转】Ubuntu安装ARM架构GCC工具链(ubuntu install ARM toolchain)最简单办法
- LeetCode Contains Duplicate III
- 使用ssh框架时出现 failed to lazily initialize 或者 no session 异常
- 人工智能搜索算法(深度优先、迭代加深、一致代价、A*搜索)
- URAL 1457. Heating Main
- Contains Duplicate
- 如何在 Ubuntu 中更改默认浏览器和 Email 客户端
- ISP Pipeline的关键模块之Demosaic( 三)
- LeetCode Contains Duplicate II
- Aizu 0005
- 错误 1 error LNK2019: 无法解析的外部符号 "public: __thiscall chain<int>::~chain<int>(void)" (??1?$chain@H@@QAE@
- rails使用devise验证
- Microsoft.AlphaImageLoader过滤评论
- Contains Duplicate II