Problem A:Rescue The Princess
Time Limit: 1 Sec
Memory Limit: 128 MB
Submit: 153
Solved: 66
[
Submit][
Status][
Discuss]
Problem A:Rescue The Princess
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 153 Solved: 66
[ Submit][ Status][ Discuss]
Description
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.
Input
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).
Output
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.
Sample Input
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
Sample Output
(-50.00,86.60) (-86.60,50.00) (-36.60,136.60) (1.00,1.00)
HINT
Source
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 153 Solved: 66
[ Submit][ Status][ Discuss]
Description
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.
Input
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).
Output
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.
Sample Input
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
Sample Output
(-50.00,86.60) (-86.60,50.00) (-36.60,136.60) (1.00,1.00)
HINT
Source
求夹角。 double a_a=atan2(b.y-a.y,b.x-a.x);
求边长 double l=sqrt((b.y-a.y)*(b.y-a.y)+(b.x-a.x)*(b.x-a.x));
#include<stdio.h>
#include<string.h>
#include<math.h>
#define pi acos(-1.0)
#include<algorithm>
using namespace std;
struct{
double x,y;
}a,b,c;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y);
double a_a=atan2(b.y-a.y,b.x-a.x);
double l=sqrt((b.y-a.y)*(b.y-a.y)+(b.x-a.x)*(b.x-a.x));
c.x=a.x+l*cos((1.0/3)*pi+a_a);
c.y=a.y+l*sin((1.0/3)*pi+a_a);
printf("(%.2f,%.2f)\n",c.x,c.y);
}
}