uva 11355(极角计算)
传送门:Cool Points
题意:给一个圆心为原点的圆和一些线段,问所有线段两端点与圆心连线构成的角度总和占总360度的百分比。
分析:首先将所有线段的两端点变成极角,然后排序(范围[-PI,PI],即从x轴负方向逆时针转一圈),如果某一线段极角值之差大于PI,构成的角度值肯定不是<AOB,而是<AOX+<XOB。因此处理好这种情况,从x轴负向走一圈计值即可。
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#define N 1010
#define PI acos(-1.0)
using namespace std;
struct node
{
double angle;
int num;
node(){}
node(double angle,int num):angle(angle),num(num){}
bool operator<(const node &a)const{
return angle<a.angle;
}
}e[N];
int tot;
void addseg(double x,double y)
{
e[tot++]=node(x,);
e[tot++]=node(y,-);
}
int main()
{
int T,n,r,cas=;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&r);
tot=;
for(int i=;i<=n;i++)
{
double x1,y1,x2,y2;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
double a1=atan2(y1,x1),a2=atan2(y2,x2);
if(a1<a2)swap(a1,a2);
if(a1-a2>PI)
{
addseg(a1,PI);
addseg(-PI,a2);
}
else addseg(a2,a1);
}
sort(e,e+tot);
int cnt=;
double ans=,last=-PI;
for(int i=;i<tot;i++)
{
if(cnt==)//前面的线段刚好成对
{
ans+=e[i].angle-last;
}
cnt+=e[i].num;
last=e[i].angle;
}
ans+=PI-last;
printf("Case %d: %.2lf%%\n",cas++,ans/(*PI)*);
}
}
uva 11355(极角计算)的更多相关文章
- UVA 11355 Cool Points( 极角计算 )
We have a circle of radius R and several line segments situated within the circumference of this cir ...
- UVa 1606 (极角排序) Amphiphilic Carbon Molecules
如果,没有紫书上的翻译的话,我觉得我可能读不懂这道题.=_=|| 题意: 平面上有n个点,不是白点就是黑点.现在要放一条直线,使得直线一侧的白点与另一侧的黑点加起来数目最多.直线上的点可以看作位于直线 ...
- UVA 11355 Cool Points(几何)
Cool Points We have a circle of radius R and several line segments situated within the circumference ...
- UVA - 1625 Color Length[序列DP 代价计算技巧]
UVA - 1625 Color Length 白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束 和模拟赛那道环形DP很想,计算这 ...
- 【转】UVa Problem 100 The 3n+1 problem (3n+1 问题)——(离线计算)
// The 3n+1 problem (3n+1 问题) // PC/UVa IDs: 110101/100, Popularity: A, Success rate: low Level: 1 / ...
- UVA - 1625 Color Length[序列DP 提前计算代价]
UVA - 1625 Color Length 白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束 和模拟赛那道环形DP很想,计算这 ...
- UVa 1606 Amphiphilic Carbon Molecules (扫描法+极角排序)
题意:平面上有 n 个点,每个点不是黑的就是白的,现在要放一个隔板,把它们分成两部分,使得一侧的白点数加上另一侧的黑点数最多. 析:这个题很容易想到的就是暴力,不妨假设隔板至少经过两个点,即使不经过也 ...
- UVa 109 - SCUD Busters(凸包计算)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- UVA 11076 Add Again 计算对答案的贡献+组合数学
A pair of numbers has a unique LCM but a single number can be the LCM of more than one possiblepairs ...
随机推荐
- PHP - 日期与时间
第10章 日期与时间 学习要点: 1.PHP日期和时间库 使用PHP编程时,与你遇到的大多数其他类型的数据相比,日期和时间有很大不同.因为日期和时间没有明确的结构,并且日期的计算和表示也很麻烦.在PH ...
- Hough变换在opencv中的应用
霍夫曼变换(Hough Transform)的原理 霍夫曼变换是一种可以检测出某种特殊形状的算法,OpenCV中用霍夫曼变换来检测出图像中的直线.椭圆和其他几何图形.由它改进的算法,可以用来检测任何形 ...
- 抽象类(abstract class)和 接口(interface)
PHP中的 抽象类(abstract class)和 接口(interface) 一. 抽象类abstract class 1 .抽象类是指在 class 前加了 abstract 关键字且存在抽象方 ...
- 解决java mail发送TXT附件被直接显示在正文中的问题
这两天遇到一个问题,关于使用java mail发送邮件的问题. 详细是这样子的:我使用java mail发送异常报告邮件,邮件中有一个包含异常日志的附件,和关于设备信息的邮件正文.假设日志为log后缀 ...
- Swift - 使用CABasicAnimation实现动画效果
1,CABasicAnimation类只有三个属性: fromValue:开始值 toValue:结束值 Duration:动画的时间 2,通过animationWithKeyPath键值对的方式设置 ...
- android设置背景图片透明
设置Activiyt为透明可以在Activity中引用系统透明主题android:theme="@android:style/Theme.Translucent" 设置背景图片透明 ...
- 跟Google学习Android开发-起始篇-与其它应用程序交互(1)
6 与其它应用程序交互 一个Android应用程序通常有多个活动.每一项活动都将显示一个用户界面,允许用户执行某种特定任务(如查看地图或者照片).为了把用户从一个活动带到另一个,你的应用必须使用Int ...
- View实现涂鸦、撤销以及重做功能
import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import j ...
- Eclipse 乱码问题 修改设置
1.工作空间的字符编码设置 2.对于任意的项目,可以右键选择属性,然后修改 3.对于任意一个文件,同样的操作,右键选择属性,然后配置字符编码
- uva 11212
非原创!!! 原作者地址:http://www.hardbird.net/?p=238