HDU 1700 Points on Cycle (几何 向量旋转)

http://acm.hdu.edu.cn/showproblem.php?pid=1700

题目大意:

  二维平面,一个圆的圆心在原点上。给定圆上的一点A,求另外两点B,C,B、C在圆上,并且三角形ABC的周长是最长的。

解题思路:

  我记得小学的时候给出个一个定理,在园里面正多边形的的周长是最长的,这个定理我不会证明。

所以这里是三角形,当三角形为正三角形的时候,周长是最长的。

因为圆心在原点,所以我就向量(x,y)绕原点逆时针旋转120度和顺时针旋转120度。给定的点A可以看成(x,y)向量。

  向量旋转是有公式的(算法竞赛入门经典 训练指南 P256)。

AC代码:

 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 }
时间: 2024-08-07 19:17:10

HDU 1700 Points on Cycle (几何 向量旋转)的相关文章

hdu 1700 Points on Cycle(坐标旋转)

http://acm.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): 1567    Accepted Submission(s): 570 Problem Description There is a cycle with its c

hdu 1700 Points on Cycle(几何)(中等)

Points on Cycle Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1992    Accepted Submission(s): 721 Problem Description There is a cycle with its center on the origin. Now give you a point on t

hdu 1700 Points on Cycle 水几何

已知圆心(0,0)圆周上的一点,求圆周上另外两点使得三点构成等边三角形. 懒得推公式,直接用模板2圆(r1=dist,r2=sqrt(3)*dist)相交水过 #include<cstdio> #include<iostream> #include<cmath> #include<algorithm> #include<iterator> using namespace std; #define eps 1e-6 typedef long lon

简单几何(向量旋转+凸包+多边形面积) UVA 10652 Board Wrapping

题目传送门 题意:告诉若干个矩形的信息,问他们在凸多边形中所占的面积比例 分析:训练指南P272,矩形面积长*宽,只要计算出所有的点,用凸包后再求多边形面积.已知矩形的中心,向量在原点参考点再旋转,角度要转换成弧度制. /************************************************ * Author :Running_Time * Created Time :2015/11/10 星期二 10:34:43 * File Name :UVA_10652.cpp

暑假集训(2)第八弹 ----- Points on Cycle(hdu1700)

Points on Cycle Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description 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 th

UVA_11178_Morley&#39;s_Theorem_(向量旋转+直线相交)

描述 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=23&page=show_problem&problem=2119 Morley定理:作三角形ABC每个内角的三等分线,相交形成三角形DEF,则三角形DEF是等边三角形. 给出三角形的三个顶点ABC的坐标,求出DEF的坐标. 11178 - Morley's Theorem Time limit: 3.000 s

一维向量旋转算法 编程珠玑 第二章

看了编程珠玑第二章,这里面讲了三道题目,这里说一下第二题,一维向量旋转算法. 题目:将一个n元一维向量(例数组)向左旋转i个位置. 解决方法:书上讲解了5种方法,自己只想起来2种最简单方法(下面讲的前两种). 1.原始方法. 从左向右依次移动一位,对所有数据平移:这样循环i次,算法最坏时间复杂度达n^2.耗时不推荐. 2.空间换时间. 顾名思义,申请一个i长度的空间,把前i半部分放到申请空间中,再把后面的所有数据向左移动i个位置,最后把申请的空间中的数据放到后半部分.浪费空间,不推荐. 3.杂技

sdut 2603: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 immedia

HDU 4772 Zhuge Liang&#39;s Password (矩阵旋转)

Zhuge Liang's Password Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 931    Accepted Submission(s): 641 Problem Description In the ancient three kingdom period, Zhuge Liang was the most famous