HDU 1104 Remainder
来源:互联网 发布:淘宝店食品流通许可证 编辑:程序博客网 时间:2024/06/05 03:59
156ms,比其他人慢好多。。
bfs暴搜
#include<cstdio>#include<iostream>#include<cstring>#include<queue>using namespace std;const int maxN=2000010;int n,k,m,step;bool vis[maxN];string anstr;struct Node{ int n,k; string str;}no;queue<Node> q;void push(int tn,char c){ if(c=='%'&&tn<0) tn+=m; tn%=(m*k); Node nn; nn.n=tn;nn.k=no.k+1;nn.str=no.str+c; if(!vis[tn+m*k]) q.push(nn); vis[tn+m*k]=true;}void bfs(){ while(!q.empty()) q.pop(); no.n=n;no.str="";no.k=0; q.push(no); int tar=(n+1)%k; if(tar<0) tar+=k; while(!q.empty()){ no=q.front();q.pop(); int cur=no.n%k; //cout<<no.n<<endl; if(cur<0) cur+=k; if(tar==cur){ step=no.k; anstr=no.str; return; } push(no.n+m,'+'); push(no.n-m,'-'); push(no.n*m,'*'); push(no.n%m,'%'); }}int main(){ while(cin>>n>>k>>m,n||k||m){ memset(vis,false,sizeof(vis)); step=0; bfs(); cout<<step<<endl; if(step) cout<<anstr<<endl; } return 0;}
- HDU 1104 Remainder
- hdu 1104 Remainder
- hdu 1104 Remainder BFS
- HDU - 1104 Remainder 搜索
- Hdu 1104 Remainder[Bfs]
- HDU 1104 Remainder
- HDU 1104 Remainder
- Remainder hdu 1104
- hdu 1104 Remainder 队列
- 【bfs】hdu 1104 Remainder
- hdu 1104 Remainder(BFS)
- HDU 1104 remainder
- 【HDU】 1104 Remainder
- hdu 1104 remainder bfs+数论
- HDU 1104 Remainder (BFS)
- HDU 1104题Remainder(bfs)
- hdu 1104 Remainder 【广度优先搜索+数论】
- hdu 1104 Remainder(BFS+数论)
- How can I find which tables reference a given table
- 数据集导出到excel 并添加背景类
- activiti---获取活动节点
- http长连接与短连接
- 双色球复式投注奖等计算算法
- HDU 1104 Remainder
- iOS5新特性:强大的Core Image(教你做自己的美图秀秀))
- NSAutoReleasePool个人理解
- 职责链模式
- buffer cache深度分析之2:内部管理机制
- Java 解压缩 zip格式的压缩文件
- Linux下动态共享库加载时的搜索路径详解
- 在用HttpWebRequest的时候,发现返回"基础连接已经关闭: 该服务器提交了 HTTP 协议冲突
- Item 02 : Prefer consts, enums, and inlines to #defines