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
一只羊在点(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; }
相关文章推荐
- GYM 100488 A. Yet Another Goat in the Garden(计算几何)
- John Paul Mueller, «Windows Administration at the Command Line for Windows 2003, Windows XP, and Windows 2000: In the Field Resu
- Use the Field in Word 2003.
- Inverses in the Field GF(2^8)
- URAL 1348 Goat in the Garden 2计算几何(解题报告)
- Tips to Survive and Progress in the Field of Software Testing
- Can you refresh a document in the Notes client after changing a rich text field?
- sgu 1348 Goat in the Garden 2【点到线段的距离】
- How To Use The New Multivalue Field In Access 2007/2010 Sunday, June 19th, 2011
- 14.64.2 表查询 Filter table by the text in a TextField
- 10 Tips to Survive and Progress in the Field of Software Testing
- Here's an example that shows how to enumerate through the features of a selection set, returning the value of each field in the attribute table except for the geometry colum.
- The top conference in computer field
- Ontology ---------- the definition of philosophy and in IT field
- ural 1084 Goat in the Garden
- Get the true value of a calculate field in SharePoint
- Unable to See the Legal Entity List of Value in the Bank Account Owner Field [ID 415529.1]
- How to filter the ManyToManyField or ForeignKey in modelForm?
- Goat in the Garden 2&&http://acm.timus.ru/problem.aspx?space=1&num=1348
- limit_choices_to a value on a field in the same model - Google Groups