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代码:
- #include<cmath>
- #include<cstdio>
- #include<algorithm>
- using namespace std;
- const double PI = acos(-1.0);
- struct Point{
- double x, y;
- Point(double x = , double y = ): x(x), y(y){}
- void scan(){
- scanf("%lf%lf", &x, &y);
- }
- void print(){
- printf("%.3lf %.3lf", x, y);
- }
- bool operator < (const Point &other){
- return y < other.y || (y == other.y && x < other.x);
- }
- };
- typedef Point Vector;
- Vector rotate(Vector A, double rad){//向量旋转公式
- return Vector(A.x * cos(rad) - A.y * sin(rad), A.y * cos(rad) + A.x * sin(rad));
- }
- int main(){
- int t;
- Point p[];
- scanf("%d", &t);
- while(t--){
- p[].scan();
- p[] = rotate(p[], PI * / );//逆时针旋转120度
- p[] = rotate(p[], -PI * / );//顺时针旋转120度
- if(p[] < p[]) swap(p[], p[]);//按题目要求输出
- p[].print(); putchar(' ');
- p[].print(); putchar('\n');
- }
- return ;
- }
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 ...
- HDU 1700 Points on Cycle (坐标旋转)
题目链接:HDU 1700 Problem Description There is a cycle with its center on the origin. Now give you a poi ...
- HDU 1700 Points on Cycle(向量旋转)
题目链接 水题,卡了下下精度. #include <cstdio> #include <iostream> #include <cmath> using names ...
- hdu 1700 Points on Cycle 水几何
已知圆心(0,0)圆周上的一点,求圆周上另外两点使得三点构成等边三角形. 懒得推公式,直接用模板2圆(r1=dist,r2=sqrt(3)*dist)相交水过 #include<cstdio&g ...
- 简单几何(向量旋转+凸包+多边形面积) UVA 10652 Board Wrapping
题目传送门 题意:告诉若干个矩形的信息,问他们在凸多边形中所占的面积比例 分析:训练指南P272,矩形面积长*宽,只要计算出所有的点,用凸包后再求多边形面积.已知矩形的中心,向量在原点参考点再旋转,角 ...
- Points on Cycle (hdu1700,几何)
Points on Cycle Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu1700 Points on Cycle
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=1700 题目: Points on Cycle Time Limit: 1000/1000 MS ...
- Points on cycle
Description There is a cycle with its center on the origin. Now give you a point on the cycle, you a ...
- HDU-1700 Points on Cycle
这题的俩种方法都是看别人的代码,方法可以学习学习,要多看看.. 几何题用到向量.. Points on Cycle Time Limit: 1000/1000 MS (Java/Others) ...
随机推荐
- VS自动添加头部注释
让VS自动生成类的头部注释,只需修改两个文集即可,一下两个路径下个有一个 Class.cs文件 D:\Program Files (x86)\Microsoft Visual Studio 14.0\ ...
- git 推送出现 "fatal: The remote end hung up unexpectedly"
原因:原因是推送的文件太大 解决方案: 注意,有时候会看不到.git文件,可能被隐藏了,在这里勾选上隐藏的项目,就可以看到了. 第一种,全局设置 在C:\Users\wang\git\.git\con ...
- sencha touch 模仿tabpanel导航栏TabBar(2013-11-7)
基于sencha touch 2.2所写 代码: /* *模仿tabpanel导航栏 */ Ext.define('ux.TabBar', { alternateClassName: 'tabBar' ...
- jconsole连接远程Tomcat应用
一.环境信息 远程tomcat:linux 64位 centos 7 上tomcat 8 本机:windows7 二.步骤 linux上,在tomcat安装目录的bin下,新建setenv.sh,内容 ...
- 通过Adb 查看当前正在运行的Activity.
extends:http://www.cnblogs.com/tt_mc/p/4269833.html adb shell dumpsys activity activities | sed -En ...
- Unity3D笔记 GUI 一
要实现的功能: 1.个性化Windows界面 2.减少个性化的背景图片尺寸 3.个性化样式ExitButton和TabButton 4.实现三个选项卡窗口 一.个性化Windows界面 1.1.创建一 ...
- git如何回滚当前修改的内容?
git如何回滚当前修改的内容? 1.打开git gui,在工具栏上点击 commit ,选择 Revert Changes, 这里可以回滚单个文件: 2.一键回滚所有修改: 打开git gui,在工 ...
- JDK1.8版本,java并发框架支持锁包括
1.自旋锁,自旋,jvm默认是10次,由jvm自己控制,for去争取锁 2.阻塞锁 被阻塞的线程,不会争夺锁 3.可重入锁,多次进入改锁的域 4.读写锁 5.互斥锁,锁本身就是互斥的 6.悲观锁,不相 ...
- yii---对数组进行分页
很多时候,我们会对多个数据进行分页处理,例如我最近开发的一个功能,系统消息,系统消息的来源是多个表,而且多个表之间的数据没有任何关联,这个时候,需要对多个表进行查询,查询返回的数据进行分页,而且采用的 ...
- you do not have permission to pull from the repository解决方法
使用git进行项目的版本管理,换了台电脑,配置了账号和邮箱后,pull一个私有项目的时候,发现一个问题: 原因分析: 这是由于没有设置Gitee的SSH公钥.在未设置SSH公钥的情况下,可以使用git ...