HDU 1700 points on cycle (geometric vector rotation)

Source: Internet
Author: User

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1700

 

Question:

A two-dimensional plane with the center of a circle on the origin. Given the point A on the circle, find the other two points B, C, B, and C on the circle, and the circumference of the Triangle ABC is the longest.

 

Solution:

I remember giving a theorem in elementary school. the circumference of the positive polygon in the garden is the longest. I will not prove this theorem.

This is a triangle. When the triangle is a positive triangle, the circumference is the longest.

Because the center of the center is at the origin, I rotate the vector (x, y) around the origin 120 degrees clockwise and 120 degrees clockwise. The given vertex A can be considered as the (x, y) vector.

Vector rotation has formulas (p256, a classic training guide for algorithm competitions ).

 

AC code:

 1 #include<cmath> 2 #include<cstdio> 3 #include<algorithm> 4 using namespace std; 5  6 const double PI = acos(-1.0); 7  8 struct Point{ 9     double x, y;10 11     Point(double x = 0, double y = 0): x(x), y(y){}12 13     void scan(){14         scanf("%lf%lf", &x, &y);15     }16 17     void print(){18         printf("%.3lf %.3lf", x, y);19     }20 21     bool operator < (const Point &other){22         return y < other.y || (y == other.y && x < other.x);23     }24 };25 26 typedef Point Vector;27 28 Vector rotate(Vector A, double rad){//向量旋转公式29     return Vector(A.x * cos(rad) - A.y * sin(rad), A.y * cos(rad) + A.x * sin(rad));30 }31 32 int main(){33     int t;34     Point p[3];35     scanf("%d", &t);36     while(t--){37         p[0].scan();38 39         p[1] = rotate(p[0], PI * 2 / 3);//逆时针旋转120度40         p[2] = rotate(p[0], -PI * 2 / 3);//顺时针旋转120度41 42         if(p[2] < p[1]) swap(p[1], p[2]);//按题目要求输出43 44         p[1].print(); putchar(‘ ‘);45         p[2].print(); putchar(‘\n‘);46     }47     return 0;48 }

 

HDU 1700 points on cycle (geometric vector rotation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.