首页 > 代码库 > poj 1254 Hansel and Grethel
poj 1254 Hansel and Grethel
Hansel and Grethel
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 2199 | Accepted: 1004 |
Description
On a warm summer afternoon, Hansel and Grethel are walking together in the fields. It is getting late and, to be honest, they are lost. Grethel is a little scared, still vividly remembering the last time they got lost in the forest. That time, an evil witch had locked them inside a house built of gingerbread and sugar! But Hansel can reassure her: this time they are well prepared. Hansel has taken a map and a compass with him!
Hansel picks two clearly outstanding features in the landscape, and uses the compass to measure the direction towards both objects. Grethel locates the objects on the map, and writes down the corresponding map coordinates. Based on this information, they will be able to accurately determine their own position on the map.
The coordinates of two marker objects, and the direction (angle from the North) towards these objects are known. Write a program which uses this data to calculate the coordinates of Hansel and Grethel’s current location.
Hansel picks two clearly outstanding features in the landscape, and uses the compass to measure the direction towards both objects. Grethel locates the objects on the map, and writes down the corresponding map coordinates. Based on this information, they will be able to accurately determine their own position on the map.
The coordinates of two marker objects, and the direction (angle from the North) towards these objects are known. Write a program which uses this data to calculate the coordinates of Hansel and Grethel’s current location.
Input
The first line of the input contains one positive number: the number of situations in which a position must be determined. Following are two lines per situation, describing the two marker objects. Each marker object is described by a line containing three integer numbers:
the x-coordinate of the object on the map (0 <= x <= 100);
the x-axis runs West-to-East on the map, with increasing values towards the East.
the y-coordinate of the object on the map (0 <= y <= 100);
the y-axis runs South-to-North on the map, with increasing values towards the North.
the direction d of the object in degrees (0 <= d <= 360);
with 0 degree = North, 90 degree = East, 180 degree = South, and so on.
To keep the position calculations accurate, Hansel makes sure that the directions of the two
objects are not exactly equal, and do not differ by exactly 180 degree.
the x-coordinate of the object on the map (0 <= x <= 100);
the x-axis runs West-to-East on the map, with increasing values towards the East.
the y-coordinate of the object on the map (0 <= y <= 100);
the y-axis runs South-to-North on the map, with increasing values towards the North.
the direction d of the object in degrees (0 <= d <= 360);
with 0 degree = North, 90 degree = East, 180 degree = South, and so on.
To keep the position calculations accurate, Hansel makes sure that the directions of the two
objects are not exactly equal, and do not differ by exactly 180 degree.
Output
One line per situation, containing the result of the position calculation: two numbers, separated by a space, each having exactly 4 digits after the decimal point. These numbers represent the x and y coordinates of the position of Hansel and Grethel (0 <= x,y <= 100). Round the numbers as usual: up if the next digit would be >= 5, down otherwise.
Sample Input
230 50 9020 40 18030 40 9620 20 150
Sample Output
20.0000 50.00007.0610 42.4110
Source
Northwestern Europe 2002
/** @Author: Lyucheng* @Date: 2017-08-06 10:53:59* @Last Modified by: Lyucheng* @Last Modified time: 2017-08-06 22:23:41*//* 题意:给你两个相对于一点的方向和坐标,让你求这点的坐标 思路:就是求两个直线的交点*/#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>#define PI 3.141592653589793238using namespace std;int n;double x,y;int x1,x2,y1,y2;double K1,K2;int deg1,deg2;double Change(int deg){ return (double)( ( (450-deg)%180 )*1.0 );}int main(){ // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); scanf("%d",&n); while(n--){ scanf("%d%d%d",&x1,&y1,°1); scanf("%d%d%d",&x2,&y2,°2); K1=tan(Change(deg1)/180*PI); K2=tan(Change(deg2)/180*PI); x=(y2-y1-x2*K2+x1*K1)/(K1-K2); y=((x2-x1)*K1*K2+y1*K2-y2*K1)/(K2-K1); printf("%.4f %.4f\n",x,y); } return 0;}
poj 1254 Hansel and Grethel
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。