hdu1700 Points on Cycle
2017-10-12 15:09
513 查看
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=1700
题目:
Points on Cycle
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2523 Accepted Submission(s): 972
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
Source 2007省赛集训队练习赛(1)
Recommend lcy
思路:
直接猜是等边三角形,然后发现确实是。
求其他两个点,直接旋转就行了。
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> using namespace std; const double PI = acos(-1.0); const double eps = 5e-4; /****************常用函数***************/ //判断ta与tb的大小关系 int sgn( double ta, double tb) { if(fabs(ta-tb)<eps)return 0; if(ta<tb) return -1; return 1; } //点 class Point { public: double x, y; Point(){} Point( double tx, double ty){ x = tx, y = ty;} }; //两点间距离 double getdis(const Point &st,const Point &se) { return sqrt((st.x - se.x) * (st.x - se.x) + (st.y - se.y) * (st.y - se.y)); } int main(void) { //freopen("in.acm","r",stdin); int t; scanf("%d",&t); Point pa,pb,pc,pp=Point(0,0); while(t--) { scanf("%lf%lf",&pa.x,&pa.y); double r = getdis(pa,pp); double ag = atan2(pa.y,pa.x); pb.x = r * cos(ag + PI * 2 / 3), pb.y = r * sin(ag + PI * 2 / 3); pc.x = r * cos(ag - PI * 2 / 3), pc.y = r * sin(ag - PI * 2 / 3); if(sgn(pb.y,pc.y)>0||(sgn(pb.y,pc.y)==0&&sgn(pb.x,pc.x)>0)) swap(pb,pc); printf("%.3f %.3f %.3f %.3f\n",pb.x,pb.y,pc.x,pc.y); } return 0; }
相关文章推荐
- HDU1700:Points on Cycle
- HDU1700 Points on Cycle(感觉很重要)
- HDU1700:Points on Cycle
- HDU1700 Points on Cycle (最大内接三角形)
- hdu1700 Points on Cycle (数学)
- HDU - 1700 :Points on Cycle
- HDU 1700 Points on Cycle(向量旋转)
- HDU 1700 || Points on Cycle (向量旋转,圆上等边三角形的周长最长
- B - Points on Cycle
- hdu 1700 Points on Cycle(坐标旋转)
- HDU-1700 Points on Cycle
- hdu 1700 Points on Cycle 水几何
- hdu 1700 Points on Cycle(几何)(中等)
- hdu 1700 Points on Cycle 水几何
- 【计算几何】 HDOJ 1700 Points on Cycle
- HDU 1700 Points on Cycle
- hdu 1700 Points on Cycle<计算几何>
- 【LeetCode】max-points-on-a-line一条线上最多点
- LeetCode__Max Points on a Line
- LeetCode Max Points on a Line