Hdu 4452 Running Rabbits 大模拟
来源:互联网 发布:windows xp系统安装包 编辑:程序博客网 时间:2024/05/16 14:41
题意:两只兔子在n*n的格子里移动,一只从左上角[1,1]开始,另一只从右下角[n,n]开始,然后经过一系列的条件:
1.他们可以它们可以沿东南西北4个方向走,但不可出格,各有各的速度,相遇时,两只兔子交换移动方向,碰边界时反向,各自还有自己的转左周期,周期一到即转左(但此时两只兔子相遇就不执行此周期转左),问K小时后两只兔子的坐标。
代码:
#include <cstdio>#include <iostream>#include <cstring>#include <string.h>#include <algorithm>#include <cmath>#include <set>const long long INF=(1ll<<60);using namespace std;struct node{ char flag; int x,y;};int main(){ int n; node First,Second; int fs,ft; int ss,st; while(scanf("%d",&n)&&n) { getchar(); scanf("%c %d %d",&First.flag,&fs,&ft); getchar(); scanf("%c %d %d",&Second.flag,&ss,&st); First.x=1; First.y=1; Second.x=n; Second.y=n; int k; scanf("%d",&k); for(int i=1; i<=k; i++) { if(First.flag=='N') { First.x-=fs; if(First.x <= 0) { First.x +=fs; First.x=fs-(First.x-1)+1; First.flag='S'; } } else if(First.flag=='S') { First.x+=fs; if(First.x > n) { First.x-=fs; First.x=n-(fs-(n-First.x)); First.flag='N'; } } else if(First.flag=='W') { First.y-=fs; if(First.y <= 0) { First.y +=fs; First.y=fs-(First.y-1)+1; First.flag='E'; } } else if(First.flag=='E') { First.y+=fs; if(First.y > n) { First.y-=fs; First.y = n-(fs-(n-First.y)); First.flag='W'; } } if(Second.flag=='N') { Second.x-=ss; if(Second.x <= 0) { Second.x +=ss; Second.x=ss-(Second.x-1)+1; Second.flag='S'; } } else if(Second.flag=='S') { Second.x+=ss; if(Second.x > n) { Second.x-=ss; Second.x=n-(ss-(n-Second.x)); Second.flag='N'; } } else if(Second.flag=='W') { Second.y-=ss; if(Second.y <= 0) { Second.y +=ss; Second.y=ss-(Second.y-1)+1; Second.flag='E'; } } else if( Second.flag=='E') { Second.y+=ss; if( Second.y > n) { Second.y-=ss; Second.y = n-(ss-(n- Second.y)); Second.flag='W'; } } if(First.x == Second.x&&First.y == Second.y) { swap(First.flag,Second.flag); } else { if(i%ft==0) { switch(First.flag) { case 'N': First.flag='W'; break; case 'S': First.flag='E'; break; case 'E': First.flag='N'; break; case 'W': First.flag='S'; break; } } if(i%st==0) { switch(Second.flag) { case 'N': Second.flag='W'; break; case 'S': Second.flag='E'; break; case 'E': Second.flag='N'; break; case 'W': Second.flag='S'; break; } } } } printf("%d %d\n",First.x,First.y); printf("%d %d\n",Second.x,Second.y); } return 0;}
- Hdu 4452 Running Rabbits 大模拟
- HDU 4452 Running Rabbits 【模拟】
- [模拟] hdu 4452 Running Rabbits
- HDU 4452 Running Rabbits [模拟]
- [hdu 4452] Running Rabbits 模拟
- hdu 4452 Running Rabbits (模拟)
- HDU Running Rabbits(模拟)
- hdu 4452 Running Rabbits (简单模拟)
- hdu 4452 Running Rabbits(模拟水题)
- HDU 4452 Running Rabbits (模拟题)
- HDU 4452 - Running Rabbits(模拟)
- HDU 4452 Running Rabbits (模拟)
- hdu 4452 Running Rabbits
- hdu 4452 Running Rabbits
- hdu 4452 Running Rabbits
- hdu - 4452 - Running Rabbits
- hdu 4452 Running Rabbits
- hdu 4452 Running Rabbits
- 关于CI中的CURD
- ffmpeg开发指南
- Assignment 10: String Algorithms
- DenyHosts保护你的linux server
- FFMPEG源码分析(二)
- Hdu 4452 Running Rabbits 大模拟
- FFMPEG源码分析(1)--持续更新
- Guava学习笔记:EventBus
- 从0开始学习quantum之3:实现WSGI的第三方库
- xcode4以後rootviewcontroller的變化
- VC6.0的兼容性问题解决方案
- Tomcat简介
- 系统集成项目管理之项目质量管理
- 基于蚁群算法求解求解TSP问题(JAVA)