B - Points on Cycle
2017-10-03 20:58
411 查看
There is a cycle with its center on the origin.
Now give you a point on the cycle, you are to find out the other two points on it, to maximize the sum of the distance between each other
you may assume that the radius of the cycle will not exceed 1000.
Input
There are T test cases, in each case there are 2 decimal number representing the coordinate of the given point.
Output
For each testcase you are supposed to output the coordinates of both of the unknow points by 3 decimal places of precision
Alway output the lower one first(with a smaller Y-coordinate value), if they have the same Y value output the one with a smaller X.
NOTE
when output, if the absolute difference between the coordinate values X1 and X2 is smaller than 0.0005, we assume they are equal.
Sample Input
2
1.500 2.000
563.585 1.251
Sample Output
0.982 -2.299 -2.482 0.299
-280.709 -488.704 -282.876 487.453
先给出自己的证明显然这三个点是要构成一个内接三角形的:
可设内接三角形三点连接圆点得到的3个角a,b,c。
周长C = ans * 2 * r
= 2 * r * (cos(a) + cos(b) + cos(c))
即求MAX(ans)
a + b + c = PI / 2
0 < a,b,c < PI / 2
a = x,b = y,c = PI/2 - x - y,0 < x,y < PI/2
ans =
cos(x) + cos(y) + cos(PI/2 - x - y)
ans =
cos(x)+cos(y)+sin(x+y)
ans =
cos(x)+cos(y)+sin(x)cos(y)+sin(y)cos(x)
ans = f(x,y) =
cos(x)+cos(y)+sin(x)cos(y)+sin(y)cos(x)
求导:
f’(x,y)|x =
-sin(x) + cos(y)cos(x) - sin(y)sin(x) = 0
f’(x,y)|y =
-sin(y) + cos(x)cos(y) - sin(x)sin(y) = 0
->-sin(x) + cos(x+y) = -sin(y) + cos(x+y) = 0
->sin(x) = sin(y) = cos(x + y)
->x = y,1 - 2sin^2(x) = sin(x)
t = sin(x)
->2t^2 + t - 1 = 0
(2t - 1)(t + 1) = 0
t = 1/2
sin(x) = 1/2 -> x = PI/6
x = y = PI / 6
f’(x,y)|xx = -cos(x)-cos(y)sin(x)-sin(y)cos(x)
f’(x,y)|xy = -cos(x)sin(y) - sin(x)cos(y)
f’(x,y)|yy = -cos(y)-cos(x)sin(y)-sin(x)cos(y)
A = -sqrt(3)r,B = -sqrt(3) / 2r,C = -sqrt(3)r
AC - B^2 = 3r^2 - 3/4r^2 > 0,A < 0,取极大值
a = b = c = PI / 6
故该内接三角形应为等边三角形
设三点分别为A,B,C,A已知。
由cos
Now give you a point on the cycle, you are to find out the other two points on it, to maximize the sum of the distance between each other
you may assume that the radius of the cycle will not exceed 1000.
Input
There are T test cases, in each case there are 2 decimal number representing the coordinate of the given point.
Output
For each testcase you are supposed to output the coordinates of both of the unknow points by 3 decimal places of precision
Alway output the lower one first(with a smaller Y-coordinate value), if they have the same Y value output the one with a smaller X.
NOTE
when output, if the absolute difference between the coordinate values X1 and X2 is smaller than 0.0005, we assume they are equal.
Sample Input
2
1.500 2.000
563.585 1.251
Sample Output
0.982 -2.299 -2.482 0.299
-280.709 -488.704 -282.876 487.453
先给出自己的证明显然这三个点是要构成一个内接三角形的:
可设内接三角形三点连接圆点得到的3个角a,b,c。
周长C = ans * 2 * r
= 2 * r * (cos(a) + cos(b) + cos(c))
即求MAX(ans)
a + b + c = PI / 2
0 < a,b,c < PI / 2
a = x,b = y,c = PI/2 - x - y,0 < x,y < PI/2
ans =
cos(x) + cos(y) + cos(PI/2 - x - y)
ans =
cos(x)+cos(y)+sin(x+y)
ans =
cos(x)+cos(y)+sin(x)cos(y)+sin(y)cos(x)
ans = f(x,y) =
cos(x)+cos(y)+sin(x)cos(y)+sin(y)cos(x)
求导:
f’(x,y)|x =
-sin(x) + cos(y)cos(x) - sin(y)sin(x) = 0
f’(x,y)|y =
-sin(y) + cos(x)cos(y) - sin(x)sin(y) = 0
->-sin(x) + cos(x+y) = -sin(y) + cos(x+y) = 0
->sin(x) = sin(y) = cos(x + y)
->x = y,1 - 2sin^2(x) = sin(x)
t = sin(x)
->2t^2 + t - 1 = 0
(2t - 1)(t + 1) = 0
t = 1/2
sin(x) = 1/2 -> x = PI/6
x = y = PI / 6
f’(x,y)|xx = -cos(x)-cos(y)sin(x)-sin(y)cos(x)
f’(x,y)|xy = -cos(x)sin(y) - sin(x)cos(y)
f’(x,y)|yy = -cos(y)-cos(x)sin(y)-sin(x)cos(y)
A = -sqrt(3)r,B = -sqrt(3) / 2r,C = -sqrt(3)r
AC - B^2 = 3r^2 - 3/4r^2 > 0,A < 0,取极大值
a = b = c = PI / 6
故该内接三角形应为等边三角形
设三点分别为A,B,C,A已知。
由cos
#include <cstdio> #include <algorithm> #include <iostream> #include <list> #include <queue> #include <cstring> #include <set> #include <map> #include <string> #include <cmath> using namespace std; #define INF 0x3f3f3f3f struct point { double x; double y; }; double dis(double a, double b, double c, double d) { return sqrt((a - c) * (a - c) + (b - d)*(b - d)); } int main() { int T; point a, b, c; cin >> T; while (T--) { cin >> a.x >> a.y; double r = sqrt(a.x * a.x + a.y * a.y); double s = r * sqrt(3); double t = sqrt(3) * a.y; b.x = (t - a.x) / 2.0; if (fabs(a.y - 0) > 1e-7) b.y = (-r * r / 2.0 - a.x * b.x) / a.y; else b.y = sqrt(r * r - b.x * b.x); c.x = (-t - a.x) / 2.0; if (fabs(a.y - 0) > 1e-7) c.y = (-r * r / 2.0 - a.x * c.x) / a.y; else c.y = -sqrt(r * r - c.x * c.x); if (fabs(c.y - b.y) < 0.0005) { if (c.x < b.x) { printf("%.3f %.3f %.3f %.3f", c.x, c.y, b.x, b.y); } else { printf("%.3f %.3f %.3f %.3f", b.x, b.y, c.x, c.y); } } else { if (c.y < b.y) { printf("%.3f %.3f %.3f %.3f", c.x, c.y, b.x, b.y); } else { printf("%.3f %.3f %.3f %.3f", b.x, b.y, c.x, c.y); } } putchar('\n'); } return 0; }
相关文章推荐
- HDU 1700 Points on Cycle
- hdu 1700 Points on Cycle(坐标旋转)
- HDU1700 Points on Cycle (最大内接三角形)
- hdu 1700 Points on Cycle 水几何
- HDU - 1700 :Points on Cycle
- hdu 1700 Points on Cycle<计算几何>
- HDU1700:Points on Cycle
- hdu 1700 Points on Cycle 水几何
- HDU1700 Points on Cycle(感觉很重要)
- hdu1700 Points on Cycle (数学)
- 【计算几何】 HDOJ 1700 Points on Cycle
- HDU 1700 || Points on Cycle (向量旋转,圆上等边三角形的周长最长
- HDU-1700 Points on Cycle
- HDU1700:Points on Cycle
- hdu1700 Points on Cycle
- hdu 1700 Points on Cycle(几何)(中等)
- HDU 1700 Points on Cycle(向量旋转)
- 【leetcode】Max Points on a Line
- [LeetCode OJ] Max Points on a Line
- 解题报告(LeetCode):Max Points on a Line