您的位置:首页 > 编程语言 > Go语言

GYM 100694 I.Goat in the Field(水~)

2017-03-25 15:59 387 查看
Description

一只羊在点(x,y)处,以1单位每秒的速度沿上下左右的某个方向跑,n个人去追羊,人的速度是1单位每秒或2单位每秒,只能横着跑或者竖着跑,不能斜着跑,问谁先追到羊

Input

首先输入两整数x和y表示羊的初始坐标,然后输入一个字符串表示羊的方向,之后输入一整数n表示要抓羊的人数,最后n行每行输入该人的名字和初始坐标(xi,yi) (1<=n,|x|,|y|,|xi|,|yi|<=1000)

Output

输出最先抓住羊的人的名字

Sample Input

0 0

LEFT

3

andrew -10 0

denis 10 0

ilia 0 10

Sample Output

andrew

Solution

经过适当坐标旋转把羊变成往上跑,每个人追羊就是先跑到同一横坐标,然后沿纵坐标追羊

Code

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
#define maxn 1111
string dir,s,name;
int x,y,n;
void deal(int &x,int &y)
{
if(dir[0]=='D')y=-y;
else if(dir[0]=='L')
{
int t=x;
x=y,y=-t;
}
else if(dir[0]=='R')
{
int t=x;
x=-y,y=t;
}
}
int main()
{
while(~scanf("%d%d",&x,&y))
{
cin>>dir;
deal(x,y);
scanf("%d",&n);
int ans=INF;
while(n--)
{
int xx,yy;
cin>>s;
scanf("%d%d",&xx,&yy);
deal(xx,yy);
int tx=(abs(xx-x)+1)/2;
int Y=y+tx,ty;
if(Y>=yy)ty=abs(Y-yy);
else ty=(abs(Y-yy)+2)/3;
if(ans>tx+ty)
ans=tx+ty,name=s;
}
cout<<name<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: