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

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看晕了吧,当然还要配图:

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

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

时间: 2024-10-23 02:29:55

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

[2013山东省第四届ACM大学生程序设计竞赛]——Alice and Bob

Alice and Bob Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Alice and Bob like playing games very much.Today, they introduce a new game. There is a polynomial like this: (a0*x^(2^0)+1) * (a1 * x^(2^1)+1)*.......*(an-1 * x^(2^(n-1))+1). T

Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)

Alice and Bob Time Limit: 1000ms   Memory limit: 65536K 题目描述 Alice and Bob like playing games very much.Today, they introduce a new game. There is a polynomial like this: (a0*x^(2^0)+1) * (a1 * x^(2^1)+1)*.......*(an-1 * x^(2^(n-1))+1). Then Alice as

sdut Mountain Subsequences 2013年山东省第四届ACM大学生程序设计竞赛

Mountain Subsequences 题目描述 Coco is a beautiful ACMer girl living in a very beautiful mountain. There are many trees and flowers on the mountain, and there are many animals and birds also. Coco like the mountain so much that she now name some letter s

[2012山东省第三届ACM大学生程序设计竞赛]——Fruit Ninja II

Fruit Ninja II 题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2416 Time Limit: 5000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Have you ever played a popular game named "Fruit Ninja"? Fruit Ninja (known as Fruit Ninja

[2012山东省第三届ACM大学生程序设计竞赛]——n a^o7 !

n a^o7 ! 题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2413 Time Limit: 1000MS Memory limit: 65536K 题目描述 All brave and intelligent fighters, next you will step into a distinctive battleground which is full of sweet and hap

angry_birds_again_and_again(2014年山东省第五届ACM大学生程序设计竞赛A题)

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2877 题目描述 The problems called "Angry Birds" and "Angry Birds Again and Again" has been solved by many teams in the series of contest in 2011 Multi-University Tr

[2012山东省第三届ACM大学生程序设计竞赛]——Mine Number

Mine Number 题目:http://acm.sdut.edu.cn/sdutoj/problem.php? action=showproblem&problemid=2410 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描写叙述 Every one once played the game called Mine Sweeping, here I change the rule. You are given an n*m ma

2014年山东省第五届ACM大学生程序设计竞赛解题报告

A  angry_birds_again_and_again http://www.sdutacm.org/sdutoj/problem.php?action=showproblem&problemid=2877 数学题,求抛物线和直线围成的面积,用积分来做. 设方程 y=ax^2+bx+c ,图中曲线经过原点,所以c=0. 对方程求导 y'=2ax+b ,  y'代表斜率,那么原点(0,0)这一点,代人y'=b,即该点的斜率,根据题意b=tan( α) 如图:在题目中x=tx这一点时,容易混,

2012年&quot;浪潮杯&quot;山东省第三届ACM大学生程序设计竞赛 Fruit Ninja I

题意: 水果忍者,给你n个水果的出现时间,出现位置,和他是否是好水果,切到好水果+1,切到坏水果-1,连续切到三次以上分数加倍. 每次只能切一刀,两刀之间的间隔大于等于m 问怎样安排能使得分最大: 解法:先求出每一秒出手能得到的最大的得分,双重暴力, 再用DP求出手时间: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <stdio.h