hdu 1700 Points on circle(三角函数应用)
来源:互联网 发布:Linux tail查找 编辑:程序博客网 时间:2024/05/27 14:14
题目链接:点击打开链接
题意:给定一个圆上的点,找另外两个圆上的点,使这三个点互相间距离最大
就是找一个等边三角形,用角度算,先算出半径r和给定的点的角度,再转120度找到另一个点的角度,然后有公式可得:
以O点为圆心的圆上内接等边三角形中x1+x2=-x3; y1+y2=-y3
此题卡了一天
首先cmath中的atan cos等函数返回值是弧度制。
atan的返回值范围是pi/2至-pi/2,所以假如角度是170度结果会返回-10度,这样再用cos,sin求点就错了,结果需要加一个pi。
还有当x<0&&y==0时,应返回-pi,但返回的是-0。
所以需要特判的就是y!=0&&x<0和y==0&&x<0的两种情况
还有本题判相等是小于0.0005要注意,有数据会卡y1>y2&&y1-y2<0.0005
本题也可以解方程做
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#define pi acos(-1.0)using namespace std;int main(){ int T; cin>>T; while(T--){ double x,y; scanf("%lf%lf",&x,&y); double r=sqrt(x*x+y*y); double a=atan(y/x); if(x<0&&y!=0)a+=pi; if(x<0&&y==0)a=-pi; a+=(pi*2*1.0/3); double x1=r*cos(a); double y1=r*sin(a); double x2=-(x+x1); double y2=-(y+y1); if((fabs(y1-y2)<0.0005&&x1<x2)||fabs(y1-y2)>=0.0005&&y1<y2) printf("%.3lf %.3lf %.3lf %.3lf\n",x1,y1,x2,y2); else printf("%.3lf %.3lf %.3lf %.3lf\n",x2,y2,x1,y1); } return 0;}
0 0
- hdu 1700 Points on circle(三角函数应用)
- HDU 1700 Points on Cycle
- HDU-1700 Points on Cycle
- hdu 1700 Points on Cycle 水几何
- hdu 1700 Points on Cycle(几何)(中等)
- PE 233 Lattice points on a circle (数论:毕格拉斯三元组(勾股数))
- HDU 4669 Mutiples on a circle (DP , 统计)
- hdu 4669 Mutiples on a circle(按位DP)
- hdu 4669 Mutiples on a circle(高效)
- POJ1981 Circle and Points(计算几何)
- poj 1981 Circle and Points (模板)
- hdu 4669 Mutiples on a circle
- HDU - 4669 Mutiples on a circle
- Circle Through Three Points
- checkio -- Three Points Circle
- poj1329 Circle Through Three Points 三角形外接圆(水)
- poj 1981 Circle and Points(圆覆盖点问题)
- POJ1329 Circle Through Three Points(解析几何,圆)
- userInteractionEnabled交互性
- 多线程的基本概念及实现方式
- mysql给用户添加查询权限
- 在 Ubuntu 12.04 上通过源代码安装 Open vSwitch (OVS)
- SVN中如何设置commit时的日志字数限制?
- hdu 1700 Points on circle(三角函数应用)
- 解决Web项目乱码的问题
- <mvc:annotation-driven />注解意义
- 九度OJ 1010 java
- httpd:unrecognized service 解决办法
- 关于数组首地址
- hashmap::begin() 坑
- quartz开源作业调度框架的配置举例
- UISegmentedControl的详细使用