1254 Hansel and Grethel
来源:互联网 发布:最全英语单词数据库 编辑:程序博客网 时间:2024/06/05 10:39
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.
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.
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
2
30 50 90
20 40 180
30 40 96
20 20 150
Sample Output
20.0000 50.0000
7.0610 42.4110
Source
Northwestern Europe 2002
/*给出两个相对于一点的方向以及坐标,求此点坐标。求出两直线交点即可*/#include<iostream>#include<math.h>using namespace std;#define PI 3.1415926535898int main(){ int n; cin >> n; while (n--) { int x1, y1, d1, x2, y2, d2; double x, y; cin >> x1 >> y1 >> d1 >> x2 >> y2 >> d2; /*斜率不存在*/ if (d1 == 0 || d1 == 180) { x = x1; y = y2 + tan((90.0 - d2)*PI / 180)*(x1 - x2); } else if (d2 == 0 || d2 == 180) { x = x2; y = y1 + tan((90.0-d1)*PI/180)*(x2 - x1); } /*斜率存在*/ else { x = (double)(y1 - y2 + x2*tan((90.0 - d2)*PI / 180) - x1*tan((90.0 - d1)*PI / 180)) / (tan((90.0 - d2)*PI / 180) - tan((90.0 - d1)*PI / 180)); y = y1 + tan((90.0 - d1)*PI / 180)*(x - x1); } printf("%.4f %.4f\n", x, y); } return 0;}
- 1254 Hansel and Grethel
- POJ 1254 Hansel and Grethel 笔记
- 1070[Hansel and Grethel]
- poj 1254 Hansel and Grethel 直线求交
- [sicily online]1070. Hansel and Grethel
- zoj 1560 Hansel and Grethel(求两条直线的交点)
- poj1254Hansel and Grethel poj1269Intersecting_Lines
- Hansel and Gretel
- 格动作韩赛尔与格蕾特:女巫猎人(Hansel and Gretel:Witch Hunters)
- " and '
- $* and $@
- AND
- AND
- & and &&
- ""and ‘’
- GetMessage () and PeekMessage () and SendMessage () and PostMessage ()
- eval and $()/``and typeset and xargs
- # and #line and __FILE__ and __LINE__
- 最近把beecloud,芝麻信用,智能门锁接入了系统。闲下来把遇到的一些坑排下,也能给后人一些指导
- [设计模式]原型模式
- Socket通信过程
- 【摩客专访】简单易用的背后是吹毛求疵的追求 | 专访“方片收集”作者田飞
- 2. TraitsUI基础
- 1254 Hansel and Grethel
- 【BigHereo 8】-----博客专家
- Spring中@Controller和@RestController之间的区别
- 开通博客了
- 0-1背包问题 DPL_1_B- 0-1 Knapsack Problem
- 动态规划(树形DP)之Anniversary party
- 【Log历练手册】Frame must be terminated with a null octet
- Android:仿苹果按钮
- [Python] wxPython 编辑框组件学习总结 (原创)