码迷,mamicode.com
首页 > 其他好文 > 详细

[2013山东省第四届ACM大学生程序设计竞赛]——Rescue The Princess

时间:2014-05-07 05:35:13      阅读:487      评论:0      收藏:0      [点我收藏+]

标签:2013山东省第四届acm大学生程序设计   rescue the princess   计算几何   山东省赛   sdut2603   

Rescue The Princess

Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^

题目描述

    Several days ago, a beast caught a beautiful princess and the princess was put in prison. To rescue the princess, a prince who wanted to marry the princess set out immediately. Yet, the beast set a maze. Only if the prince find out the maze’s exit can he save the princess.

    Now, here comes the problem. The maze is a dimensional plane. The beast is smart, and he hidden the princess snugly. He marked two coordinates of an equilateral triangle in the maze. The two marked coordinates are A(x1,y1) and B(x2,y2). The third coordinate C(x3,y3) is the maze’s exit. If the prince can find out the exit, he can save the princess. After the prince comes into the maze, he finds out the A(x1,y1) and B(x2,y2), but he doesn’t know where the C(x3,y3) is. The prince need your help. Can you calculate the C(x3,y3) and tell him?

输入

    The first line is an integer T(1 <= T <= 100) which is the number of test cases. T test cases follow. Each test case contains two coordinates A(x1,y1) and B(x2,y2), described by four floating-point numbers x1, y1, x2, y2 ( |x1|, |y1|, |x2|, |y2| <= 1000.0).
    Please notice that A(x1,y1) and B(x2,y2) and C(x3,y3) are in an anticlockwise direction from the equilateral triangle. And coordinates A(x1,y1) and B(x2,y2) are given by anticlockwise.

输出

    For each test case, you should output the coordinate of C(x3,y3), the result should be rounded to 2 decimal places in a line.

示例输入

4
-100.00 0.00 0.00 0.00
0.00 0.00 0.00 100.00
0.00 0.00 100.00 100.00
1.00 0.00 1.866 0.50

示例输出

(-50.00,86.60)
(-86.60,50.00)
(-36.60,136.60)
(1.00,1.00)

来源

2013年山东省第四届ACM大学生程序设计竞赛
题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2603


这道题就是当初我卡的那道。。很简单,就是自己*%&了。。。

当时不知道脑子咋了,愣是看了好久好久。。。

无论计算几何还是解析几何都可以做出来。

用计算几何搞得这道题。

题意: 给你等边三角形的两个点,逆时针的第三个点坐标。

用的公式:OB=(x*cosα-y*sinα,x*sinα+y*cosα)

这是逆时针的,还有顺时针的:

OA=(y*sinα - x*cosα,x*sinα+y*cosα)

OA,OB看晕了吧,当然还要配图:

bubuko.com,布布扣

然后,这道题就迎刃而解了。。。

O,还有,这道题会卡精度。。。π值最好用acos(-1)来求,

反正我用3.1415926不行(我只能背到这了,o(╯□╰)o)


/**************************************
***************************************
*        Author:Tree                  *
*From :http://blog.csdn.net/lttree    *
* Title : Rescue The Princess         *
*Source: 第四届山东省ACM比赛         *
* Hint  : 计算几何                   *
***************************************
**************************************/
#include <stdio.h>
#include <cmath>
using namespace std;
#define Pi acos(-1.0)

struct Point
{
    double x,y;
};
struct Line
{
    Point a,b;
};
// 向量l,绕l.a点逆时针转a弧度,返回转到的点。
// OB=(x*cosα-y*sinα,x*sinα+y*cosα)
Point rotate_anticw(Line l,double a)
{
    Point p;
    p.x = ( l.b.x-l.a.x ) * cos(a) - ( l.b.y-l.a.y ) * sin(a);
    p.y = ( l.b.x-l.a.x ) * sin(a) + ( l.b.y-l.a.y ) * cos(a);
    p.x += l.a.x;
    p.y += l.a.y;
    return p;
}
// 向量l,绕l.a点顺时针转a弧度,返回转到的点。
// OA=(y*sinα - x*cosα,x*sinα+y*cosα)
Point rotate_cw(Line l,double a)
{
    Point p;
    p.x = ( l.b.y-l.a.y ) * sin(a) - ( l.b.x-l.a.x ) * cos(a);
    p.y = ( l.b.x-l.a.x ) * sin(a) + ( l.b.y-l.a.y ) * cos(a);
    p.x += l.a.x;
    p.y += l.a.y;
    return p;
}
int main()
{
    int t;
    Point c;
    Line l;
    scanf("%d",&t);
    while( t-- )
    {
        scanf("%lf%lf%lf%lf",&l.a.x,&l.a.y,&l.b.x,&l.b.y);
        c = rotate_anticw(l,60*Pi/180);
        printf("(%.2lf,%.2lf)\n",c.x,c.y);
    }
    return 0;
}


[2013山东省第四届ACM大学生程序设计竞赛]——Rescue The Princess,布布扣,bubuko.com

[2013山东省第四届ACM大学生程序设计竞赛]——Rescue The Princess

标签:2013山东省第四届acm大学生程序设计   rescue the princess   计算几何   山东省赛   sdut2603   

原文地址:http://blog.csdn.net/lttree/article/details/25057853

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!