HDU 4452 Running Rabbits
来源:互联网 发布:音视频转换器mac 编辑:程序博客网 时间:2024/05/18 08:56
传送门:HDU 4452
比较简单的模拟题,可是我刚开始读题理解有问题。题目理解正确才是硬道理
#include <iostream>#include <map>#include <cstdio>#include <cstring>using namespace std;map<char,int> mp;int As,Az,Bs,Bz,N,t;int op[4][2] = {-1,0,0,-1,1,0,0,1}; // N,W,S,Evoid dfs(int Ac,int Ax,int Ay,int Ap,int Bc,int Bx,int By,int Bp,int tot){ if(tot == t) { printf("%d %d\n%d %d\n",Ax,Ay,Bx,By); return; } Ax += op[Ac][0]*As; Ay += op[Ac][1]*As; if(Ax<1) { Ax = 2-Ax; Ac = (Ac+2)%4; if(Ax>N) { Ax = 2*N-Ax; Ac = (Ac+2)%4; } } else if(Ax>N) { Ax = 2*N-Ax; Ac = (Ac+2)%4; if(Ax<1) { Ax = 2-Ax; Ac = (Ac+2)%4; } } if(Ay <1) { Ay =2 - Ay; Ac = (Ac+2)%4; if(Ay>N) { Ay = 2*N-Ay; Ac = (Ac+2)%4; } } else if(Ay>N) { Ay = 2*N-Ay; Ac = (Ac+2)%4; if(Ay <1) { Ay =2 - Ay; Ac = (Ac+2)%4; } } Ap++; Bx += op[Bc][0]*Bs; By += op[Bc][1]*Bs; if(Bx<1) { Bx =2 - Bx; Bc = (Bc+2)%4; if(Bx>N) { Bx=2*N-Bx; Bc = (Bc+2)%4; } } else if(Bx>N) { Bx=2*N-Bx; Bc = (Bc+2)%4; if(Bx<1) { Bx =2 - Bx; Bc = (Bc+2)%4; } } if(By <1) { By =2-By; Bc = (Bc+2)%4; if(By>N) { By = 2*N-By; Bc = (Bc+2)%4; } } else if(By>N) { By = 2*N-By; Bc = (Bc+2)%4; if(By <1) { By =2-By; Bc = (Bc+2)%4; } } Bp++; if(Ax==Bx&&Ay==By) { swap(Ac,Bc); //swap(As,Bs); //swap(Az,Bz); if(Ap==Az) { //Ac = (Ac+1)%4; Ap = 0; } if(Bp==Bz) { // Bc = (Bc+1)%4; Bp = 0; } } else { if(Ap==Az) { Ac = (Ac+1)%4; Ap = 0; } if(Bp==Bz) { Bc = (Bc+1)%4; Bp = 0; } } tot ++; dfs( Ac, Ax, Ay, Ap, Bc, Bx, By, Bp, tot);}int main(){ char o; int Ac,Bc; mp['N'] = 0; mp['W'] = 1; mp['S'] = 2; mp['E'] = 3; while(scanf("%d",&N)&&N) { getchar(); o = getchar(); Ac = mp[o]; scanf(" %d %d",&As,&Az); As %=N; getchar(); o = getchar(); Bc = mp[o]; scanf("%d %d",&Bs,&Bz); Bs %=N; scanf("%d",&t); dfs(Ac,1,1,0,Bc,N,N,0,0); } return 0;}
0 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 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 (简单模拟)
- hdu 4452 Running Rabbits(模拟水题)
- 安装python模块,常用安装方式
- JS获取下拉框的值
- There is no getter for property named 'XX' in 'class java.lang.String'
- OKHttpClient使用示例
- C#之XML基础 innertext与innerxml的区别
- HDU 4452 Running Rabbits
- codeforces 723C. Polycarp at the Radio [模拟]【杂类】
- ubuntu14.04安装Ansible
- python操作Excel读写--使用xlrd
- 1052. Linked List Sorting (25)
- 掌握知识
- 简单计算器的功能实现
- 解决设置了float了的子元素的父级边框和背景不显示的问题
- 安卓开发——SQLite数据库的使用