USACO Section 2.4 The Tamworth Two - 又犯2了..又把一个简单的问题整复杂了..
来源:互联网 发布:巨人网络公司地址 编辑:程序博客网 时间:2024/05/01 23:18
做了好几个小时~~开始的做法是先找出C走的路径~~并记下循环节~~~然后再走F..走到一个点就判断下是不是能同时~~开了2个4维数组~~代码码了120多行~~结果还是没调出来...要吐了..
刚才突然开窍了~~这不同时记步数同时走~~啥时候一样就ok了~~~呃~~十分钟解决~~矮油~~
Program:
/* ID: zzyzzy12 LANG: C++ TASK: ttwo*/ #include<iostream> #include<istream>#include<stdio.h> #include<string.h> #include<math.h> #include<stack>#include<algorithm> #include<queue> using namespace std; const int face[4][2]={{-1,0},{0,1},{1,0},{0,-1}};char mar[12][12];int s[12][12][12][12],c[12][12][12][12];int y,x,step,k,ty,tx,my,mx;bool judge(int ty,int tx){ if (ty==10 || ty<0 || tx==10 || tx<0 || mar[ty][tx]=='*') return false; return true;} void choose(int *y,int *x,int *k){ ty=*y+face[*k][0]; tx=*x+face[*k][1]; if (!judge(ty,tx)) { *k=(*k+1)%4; return; } *y=ty; *x=tx; return;} int getanswer(){ int step=0,ty,tx,x1,y1,x2,y2,k1=0,k2=0; for (y1=0;y1<10;y1++) { for (x1=0;x1<10;x1++) if (mar[y1][x1]=='C') break; if (x1!=10) break; } for (y2=0;y2<10;y2++) { for (x2=0;x2<10;x2++) if (mar[y2][x2]=='F') break; if (x2!=10) break; } while (step<10001) { step++; choose(&y1,&x1,&k1); choose(&y2,&x2,&k2); if (x1==x2 && y1==y2) return step; } return 0;}int main(){ freopen("ttwo.in","r",stdin); freopen("ttwo.out","w",stdout); for (int i=0;i<10;i++) scanf("%s",mar[i]); printf("%d\n",getanswer()); return 0; }
- USACO Section 2.4 The Tamworth Two - 又犯2了..又把一个简单的问题整复杂了..
- USACO 2.4 The Tamworth Two<简单图问题>
- USACO section 2.4 The Tamworth Two(算模拟吧)
- USACO Section 2.4 The Tamworth Two (BFS模拟)
- USACO-Section 2.4 The Tamworth Two(模拟)
- chapter 2 section 2.4 The Tamworth Two
- USACO--2.4The Tamworth Two
- USACO 2.4 The Tamworth Two
- 又犯了不该犯的错误
- usaco-The Tamworth Two
- USACO The Tamworth Two
- usaco The Tamworth Two
- usaco:The Tamworth Two
- USACO-The Tamworth Two
- USACO The Tamworth Two
- USACO-The Tamworth Two
- 今天又犯了一个错,遍历DOM的时候。。
- USACO 2.4.1 The Tamworth Two
- HDU4132 How Far Can Drive At Most 离散化+树状数组/线段树
- java设计模式之单例模式Singleton
- 【Doing4】ACM之Java新手速成
- java统计指定文件的大小以及包含的文件夹和文件数
- 工作中运用的tomcat 配置、使用介绍
- USACO Section 2.4 The Tamworth Two - 又犯2了..又把一个简单的问题整复杂了..
- SSH服务器安装及配置
- Flex和spring集成时需要的SpringFactory
- 设置zencart当前页面位置导航(zencart面包屑)
- xml节点 增删改
- Linux Platform Device and Driver,platform_add_devices()->platform_driver_register()
- 进程互斥软件算法(Lamport面包店算法和Eisenberg算法)
- HTML JS转义字符
- Xml文档(一)