USACO2.4.1 The Tamworth Two (ttwo)
来源:互联网 发布:surface rt ubuntu 编辑:程序博客网 时间:2024/06/05 02:48
记录方向和坐标,直接模拟,直到相遇。如何判断永远不相遇呢?
对于牛或者人状态只有(10*10*4)400种,所以对于整个过程最多有(400*400)160000种状态。
也就是说,如果超过160000步,那么肯定会出现有的状态出现了2次以上,那么就肯定是一个死循环,永远不会相遇。
/*ID:xsy97051LANG:C++TASK:ttwo*/#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;char dat[11][11],go[4][2]={{-1,0},{0,1},{1,0},{0,-1}};int main(){freopen("ttwo.in","r",stdin);freopen("ttwo.out","w",stdout);memset(dat,0,sizeof(dat)); int cx,cy,fx,fy,dc=0,df=0; for(int i=1;i<=10;i++) for(int j=1;j<=10;j++) { char c; cin>>c; if(c=='*') { dat[i][j]=1; continue;} if(c=='F') { fx=i; fy=j;} if(c=='C') { cx=i; cy=j;} } int time=0,x,y; while(time++<160000) { if((fx==cx)&&(fy==cy)) break; x=fx+go[df][0]; y=fy+go[df][1]; if((dat[x][y]==1)||(x<1)||(x>10)||(y<1)||(y>10)) df=(df+1)%4; else { fx=x; fy=y; } x=cx+go[dc][0]; y=cy+go[dc][1]; if((dat[x][y]==1)||(x<1)||(x>10)||(y<1)||(y>10)) dc=(dc+1)%4; else { cx=x; cy=y; } } if(time<=160000) cout<<time-1<<endl; else cout<<0<<endl;return 0;}
0 0
- USACO2.4.1 The Tamworth Two (ttwo)
- USACO2.4.1 The Tamworth Two (ttwo)
- USACO 2.4 The Tamworth Two (ttwo)
- [USACO2.4]两只塔姆沃斯牛 The Tamworth Two
- usaco-The Tamworth Two
- USACO The Tamworth Two
- usaco The Tamworth Two
- The Tamworth Two
- usaco:The Tamworth Two
- USACO-The Tamworth Two
- The Tamworth Two
- USACO The Tamworth Two
- USACO-The Tamworth Two
- 【其他】【USACO】The Tamworth Two
- USACO--2.4The Tamworth Two
- USACO 2.4 The Tamworth Two
- usaco The Tamworth Two 两只塔姆沃斯牛
- chapter 2 section 2.4 The Tamworth Two
- I/O中断初始化顺序
- {转}用python写MapReduce函数——以WordCount为例
- echarts加载动态数据---实时统计
- [leetcode] String to Integer (atoi)
- 【iOS开发】30多个iOS常用动画,带详细注释
- USACO2.4.1 The Tamworth Two (ttwo)
- C#中如何捕捉对话框的文本内容
- UVA 10304 Optimal Binary Search Tree (区间dp)
- uva 1335 - Beijing Guard
- Android 解压html压缩数据
- C语言 链表
- 南阳62 笨小熊
- 设计模式之Decorator(油漆工)
- centos防火墙添加端口8080 版本2.6.32-279.el6.x86_64