POJ 1067(广搜水题)
来源:互联网 发布:淘宝网的网址是多少 编辑:程序博客网 时间:2024/05/18 03:14
参考某大牛的算法,还写这么久,真悲剧
#include <iostream>#include <cstdio>#include <cstdlib>using namespace std;#define Afull 1#define Bfull 2#define Aempty 3#define Bempty 4#define AtoB 5#define BtoA 6int head,tail;char step[7][10]= {"0","fill A","fill B","empty A","empty B","pour A B","pour B A"};struct state{ int mark; int a; int b; struct state *front;};state Q[100000];void enq(state a){ Q[head++]=a;}state outq(){ return Q[tail++];}int check(state a){ for(int i=0; i<head; i++) { if(Q[i].a==a.a&&Q[i].b==a.b) return 1; } return 0;}int empty(){ if(head==tail) return 1; else return 0;}int main(){ int A,B,N,i; state temp,*point,s,*search,*result[100000]; while(scanf("%d%d%d",&A,&B,&N)!=EOF) { head=0; tail=0; temp.a=0; temp.b=0; temp.mark=0; temp.front=NULL; enq(temp); while(!empty()) { temp=outq(); point=&Q[tail-1]; if(temp.a==N||temp.b==N) break; s=temp; s.a=A; if(!check(s)&&temp.a!=A) { s.front=point; s.mark=Afull; enq(s); } s=temp; s.b=B; if(!check(s)&&temp.b!=B) { s.front=point; s.mark=Bfull; enq(s); } s=temp; s.a=0; if(!check(s)&&temp.a) { s.front==point; s.mark=Aempty; enq(s); } s=temp; s.b=0; if(!check(s)&&temp.b) { s.front=point; s.mark=Bempty; enq(s); } s=temp; if(s.a!=0&&s.b<B&&s.a<=B-s.b) { s.b+=s.a; s.a=0; if(!check(s)) { s.front=point; s.mark=AtoB; enq(s); } } else { if(s.a!=0&&s.b<B) { s.a-=(B-s.b); s.b=B; if(!check(s)) { s.front=point; s.mark=AtoB; enq(s); } } } if(s.b!=0&&s.a<A&&s.b<=A-s.a) { s.a+=s.b; s.b=0; if(!check(s)) { s.front=point; s.mark=BtoA; enq(s); } } else { if(s.b!=0&&s.a<A) { s.a=A; s.b-=(A-s.b); if(!check(s)) { s.front=point; s.mark=BtoA; enq(s); } } } } search=point; for(i=0; search!=NULL; i++) { result[i]=search; search=search->front; } for(i-=2; i>=0; i--) puts(step[result[i]->mark]); printf("success\n"); } return 0;}
- POJ 1067(广搜水题)
- POJ 1067(威佐夫博奕)
- poj 1067
- poj 1067
- poj 1067
- poj 1067
- POJ 1067
- poj 1067
- POJ 1067
- POJ 1067 取石子游戏 (博弈)
- poj 1067取石子(威佐夫博奕)
- POJ 1067(取石子游戏)
- POJ-1067 取石子游戏(威佐夫博奕)
- POJ - 1067 - 取石子游戏 (威佐夫博奕)
- poj 1061 + poj 2115 + poj 2142 (exgcd)
- 小比赛(POJ 2992,UVALive 4108,POJ 2263,POJ 3617,HDU 5305,POJ 1988,POJ 1679,POJ 3481)
- 树状数组(poj 1195,poj 3321)
- poj 1129 (类似poj 1419)
- Valgrind 使用简单说明(ZZ)
- svn中import 从本地编码转换到UTF8失败以及checkout到本地后svn 工作副本已经锁定,尚未纳入版本控制解决
- 数据库备份脚本shell
- 经济萧条的时代下,买彩票减压可行吗?
- VS2008 if else等语句块的收缩
- POJ 1067(广搜水题)
- 让IIS6.0支持PHP的配置方法
- 虚析构函数和protected析构函数
- 国外仿照flipboard的一个jquery操作示例
- 数据仓库建设失败的主要原因(鲁百年)
- iframe / frame
- SVN服务器搭建
- 分享100佳精美的作品集网站设计案例
- eclipse xml自动提示