USACO Section 2.4 The Tamworth Two - 又犯2了..又把一个简单的问题整复杂了..
2011-12-01 20:43
239 查看
做了好几个小时~~开始的做法是先找出C走的路径~~并记下循环节~~~然后再走F..走到一个点就判断下是不是能同时~~开了2个4维数组~~代码码了120多行~~结果还是没调出来...要吐了..
刚才突然开窍了~~这不同时记步数同时走~~啥时候一样就ok了~~~呃~~十分钟解决~~矮油~~
Program:
刚才突然开窍了~~这不同时记步数同时走~~啥时候一样就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 2.4 The Tamworth Two<简单图问题>
- USACO Section 2.4 The Tamworth Two (BFS模拟)
- USACO Section 2.4 Fractions to Decimals - 思维不要局限..问题想简单点..
- 朋友是一个问题简单而又复杂的概念
- USACO section2.4 The Tamworth Two题解&代码
- 一个看似简单却复杂的问题:求两个字符串的 左向右匹配 所有的 最长连续的 公共子字符串( 在每个字符串中先后次序相同的) 序列
- 为复杂的问题找一个简单的答案
- USACO 2.4 The Tamworth Two
- USACO 2.4 The Tamworth Two (ttwo)
- 分布式消息队列RocketMQ&Kafka -- 消息的“顺序消费”-- 一个看似简单的复杂问题
- 【USACO 2.4】The Tamworth Two
- USACO 2.4 The Tamworth Two(乱搞)
- 分布式消息队列RocketMQ&Kafka -- 消息的“顺序消费”-- 一个看似简单的复杂问题
- 对于每个复杂的问题都会有一个简单但不准确的答案
- USACO Section 2.4 The Tamworth Two
- USACO section 2.4 The Tamworth Two(算模拟吧)
- USACO - Chapter2 Section 2.4 - The Tamworth Two
- USACO--2.4The Tamworth Two
- USACO 2.4 The Tamworth Two ttwo