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.

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

/*
* @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.141592653589793238

using 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,&deg1);
        scanf("%d%d%d",&x2,&y2,&deg2);
        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;
}
时间: 2024-12-29 11:19:37

poj 1254 Hansel and Grethel的相关文章

poj 1254 推箱子

New~ 欢迎“热爱编程”的高考少年——报考杭州电子科技大学计算机学院 关于2015年杭电ACM暑期集训队的选拔 欢迎参加: 浙江杭电{安控杯}Hackthon 推箱子 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6027    Accepted Submission(s): 1721 Problem Description 推箱子

ACM训练方案-POJ题目分类

ACM训练方案-POJ题目分类 博客分类: 算法 ACM online Judge 中国: 浙江大学(ZJU):http://acm.zju.edu.cn/ 北京大学(PKU):http://acm.pku.edu.cn/JudgeOnline/ 杭州电子科技大学(HDU):http://acm.hdu.edu.cn/ 中国科技大学(USTC):http://acm.ustc.edu.cn/ 北京航天航空大学(BUAA)http://acm.buaa.edu.cn/oj/index.php 南京

转载:poj题目分类(侵删)

转载:from: POJ:http://blog.csdn.net/qq_28236309/article/details/47818407 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K–0.50K:中短代码:0.51K–1.00K:中等代码量:1.01K–2.00K:长代码:2.01K以上. 短:1147.1163.1922.2211.2215.2229.2232.2234.2242.2245.2262.2301.2309.2313.2334.2346.2348

poj题库分类

初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推.     (5)构造法.(poj3295)     (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:     (1)图的深度优先遍历和广度优先遍历.     (2)最短路径算法(dijkstra,bellman-ford,floyd,hea

POJ题目(转)

http://www.cnblogs.com/kuangbin/archive/2011/07/29/2120667.html 初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推.     (5)构造法.(poj3295)     (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:     (

Poj 题目分类

初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推.     (5)构造法.(poj3295)     (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:     (1)图的深度优先遍历和广度优先遍历.     (2)最短路径算法(dijkstra,bellman-ford,floyd,hea

POJ题目分类(转)

初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推.     (5)构造法.(poj3295)     (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:     (1)图的深度优先遍历和广度优先遍历.     (2)最短路径算法(dijkstra,bellman-ford,floyd,hea

北大POJ题库使用指南

原文地址:北大POJ题库使用指南 北大ACM题分类主流算法: 1.搜索 //回溯 2.DP(动态规划)//记忆化搜索 3.贪心 4.图论 //最短路径.最小生成树.网络流 5.数论 //组合数学(排列组合).递推关系.质因数法 6.计算几何 //凸壳.同等安置矩形的并的面积与周长.凸包计算问题 8.模拟 9.数据结构 //并查集.堆.树形结构 10.博弈论 11.CD有正气法题目分类: 1. 排序 1423, 1694, 1723, 1727, 1763, 1788, 1828, 1838, 1

poj循序渐进300题

主要是整理起来自己用的.网上有多个版本. 初级: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. (5)构造法.(poj3295) (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996) 二.图算法: (1)图的深度优先遍历和广度优先遍历. (2)最短路径算法(dijkstra,bellman-ford,floyd,heap+dijkstr