zoukankan      html  css  js  c++  java
  • 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

    /*
    * @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
    ",x,y);
        }
        return 0;
    }
  • 相关阅读:
    html5储存篇(二)
    html5 存储篇(一)
    【刷题计划1】【poj分类转载】【8月20号开始】
    【如何搭建一个属于自己的独立博客~~~基于windows系统,使用wordpress建站】【弱菜一枚~~大神请路过】
    第六章 6.6 图的应用
    第六章 6.5 图的遍历
    第六章 6.4 图的存储结构
    poj 2488 A Knight's Journey 【dfs】【字典序】【刷题计划】
    【Educational Codeforces Round 33 B】Beautiful Divisors
    【 Educational Codeforces Round 33 A】Chess For Three
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/7296262.html
Copyright © 2011-2022 走看看