# 加载中...

• 博客等级：
• 博客积分：0
• 博客访问：33,316
• 关注人气：17
• 获赠金笔：0支
• 赠出金笔：0支
• 荣誉徽章：

## HDU4452  （Running Rabbits）2012金华赛区K 简单模拟题

(2012-10-29 22:47:12)

### 杂谈

#include <iostream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <algorithm>
using namespace std;

typedef struct
{
int x,y;
}element;

element tom , jerry;
int setoff[4][2] = {{-1,0},{0,-1},{1,0},{0,1}};
int n;
int des_1 , speed_1 , ture_time_1; // N 0; W 1  ; s 2 ; E3;
int des_2 , speed_2 , ture_time_2;
int times = 0;
int tmp_time = 0;

inline void runing()
{
for(int tmp_time = 1; tmp_time <= times ; ++tmp_time)
{

//方向行走以及掉头   先判tom
element flag;
flag.x = tom.x;
flag.y = tom.y;
flag.x += speed_1*setoff[des_1][0];
flag.y += speed_1*setoff[des_1][1];

if( flag.x < 1 || flag.x > n || flag.y < 1 ||flag.y > n )//越界状况
{
// N 0; W 1  ; s 2 ; E3;
if(!des_1)  // -1 , 0
{
tom.x = 2 - flag.x;//speed_1 - tom.x + 1;
}
else if(des_1 == 1)//0 , -1
{
tom.y = 2 - flag.y;
}
else if(des_1 == 2)//1,0
{
tom.x = 2*n - speed_1 - tom.x ;
}
else if(des_1 == 3)
{
tom.y = 2*n - speed_1 - tom.y ;
}
des_1 = (des_1 + 2)%4;

else
tom.x = flag.x , tom.y = flag.y;

flag.x = jerry.x;
flag.y = jerry.y;
flag.x += speed_2*setoff[des_2][0];
flag.y += speed_2*setoff[des_2][1];

if( flag.x < 1 || flag.x > n || flag.y < 1 ||flag.y > n )//越界状况
{
// N 0; W 1  ; s 2 ; E3;
if(!des_2)  // -1 , 0
{
jerry.x = 2 - flag.x;
}
else if(des_2 == 1)//0 , -1
jerry.y = 2 - flag.y;
else if(des_2 == 2)//1,0
jerry.x = 2*n - speed_2 - jerry.x ;
else if(des_2 == 3)
jerry.y = 2*n - speed_2 - jerry.y ;
des_2 = (des_2 + 2)%4;

else
jerry.x = flag.x , jerry.y = flag.y;

//先判miss else再判转弯
if(tom.x == jerry.x && tom.y == jerry.y)//miss了
swap(des_1 , des_2);
else  // 没miss
{
if(tmp_time % ture_time_1 == 0)
des_1 = (des_1+1)%4;
if(tmp_time % ture_time_2 == 0 )
des_2 = (des_2+1)%4;
}

}
}

int main()
{

while(scanf("%d",&n),n)
{
char ch ;
cin>>ch>>speed_1>>ture_time_1;
if(ch == 'E')// N 0; W 1  ; s 2 ; E3;
des_1 = 3;
else if(ch == 'S')
des_1 = 2;
else if(ch == 'W')
des_1 = 1;
else if(ch == 'N')
des_1 = 0;

cin>>ch>>speed_2>>ture_time_2;
if(ch == 'E')// N 0; W 1  ; s 2 ; E3;
des_2 = 3;
else if(ch == 'S')
des_2 = 2;
else if(ch == 'W')
des_2 = 1;
else if(ch == 'N')
des_2 = 0;

scanf("%d",×);
tom.x = 1 , tom.y = 1;
jerry.x = n , jerry.y = n;

tmp_time = 0;
runing();

cout<<tom.x<<" "<<tom.y<<endl;
cout<<jerry.x<<" "<<jerry.y<<endl;
}
return 0;
}

0

• 评论加载中，请稍候...

发评论

以上网友发言只代表其个人观点，不代表新浪网的观点或立场。

新浪BLOG意见反馈留言板　电话：4000520066 提示音后按1键（按当地市话标准计费）　欢迎批评指正

新浪公司 版权所有