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 ...
随机推荐
- Vistual Studio 2012更换皮肤
早就装上VS2012了,可是除了在家里练习玩玩的时候使用外,在公司都还在用2010,也没好好研究过2012.这两天把公司的电脑换了系统,也就把vs换成了2012.可是看着不是白白的皮肤就是深色的皮肤, ...
- SonicUI在MFC中的使用
SonicUI是一个GUI引擎,提供了一些简单的UI组件实现高效率的UI效果,例如:自绘按钮.异形窗体.动画.超链接和图像操作方法.此项目作者开源到CodeProject,地址为:http://www ...
- windows下安装mysql5.6.13的主从复制
如下操作均在vmware 虚拟机中winows xp 测试成功 中间走了很多弯路,网上的很多资料都是针对5.1以前的版本,在新版中根本无法使用,所以根据自己的实践整理了这篇文章 主服务:192.168 ...
- nest expression & Pyparsing
http://pyparsing.wikispaces.com/ http://bbs.csdn.net/topics/330052586 C++ boost "<([^<> ...
- ASP.NET - 用户控件制作
首先添加用户控件: 在里面写上代码: <%@ Control Language="C#" AutoEventWireup="true" CodeBehin ...
- Eclipse用法和技巧十三:自动生成的TODO注释1
使用eclipse的快捷键自动生成的代码,经常有这样的注释. 一眼看上去这个注释和一般的注释并无什么差别,不过TODO这个字符串的颜色不一样,应该有些内容.TODO是eclipse中提供的一种任务标签 ...
- Silverlight技术调查(1)——Html向Silverlight传参
原文 Silverlight技术调查(1)——Html向Silverlight传参 近几日项目研究一个很牛的富文档编辑器DXperience RichEdit组件,调查环境为Silverlight4. ...
- canvas 多种形状绘图方法
function canvasUploadImg(image,imageName,imgType,callbackfn){ var img_width = image.width; var img_h ...
- MySql截取DateTime字段的日期值
用 DATE_FORMAT 来格式化日期字段 SELECT DATE_FORMAT(crt_time,'%Y-%m-%d') FROM ad_n_advertise_t
- Incompatible namespaceIDs或连接被对端重置异常的解决
Workaround 1: Start from scratch I can testify that the following steps solve this error, but the si ...