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 ...
随机推荐
- 利用T4模版生成EF实体
直接上代码,只需要修改EF实体的地址就可以了. <#@ template language="C#" debug="false" hostspecific ...
- System.gc
Java中的内存分配是随着new一个新的对象来实现的,这个很简单,而且也还是有一些可以“改进”内存回收的机制的,其中最显眼的就是这个System.gc()函数. 乍一看这个函数似乎是可以进行垃圾回收的 ...
- 【解决方法】System.IO.FileNotFoundException
错误日志 See the end of this message for details on invoking just-in-time (JIT) debugging instead of thi ...
- [hadoop系列]Pig的安装和简单演示样例
inkfish原创,请勿商业性质转载,转载请注明来源(http://blog.csdn.net/inkfish ).(来源:http://blog.csdn.net/inkfish) Pig是Yaho ...
- 让office2003和office2010共存的方法【转】
前段时间由于工作需要安装office2010,每次打开word都会弹出安装配置界面,反之亦然.于是我在网上找了不少资料.也试了不少方法,终于试用了以下方法得以解决,以下来源于网络. 电脑上同时安装了O ...
- Spring中的p标签(转)good
Spring的p标签是基于XML Schema的配置方式,目的是为了简化配置方式. 在XML文件头部添加xmlns:p="http://www.springframework.org/sch ...
- boost asio io_service学习笔记
构造函数 构造函数的主要动作就是调用CreateIoCompletionPort创建了一个初始iocp. Dispatch和post的区别 Post一定是PostQueuedCompletionSta ...
- 首款符合PICO-ITX规格的A20开源硬件开发平台
http://mp.weixin.qq.com/mp/appmsg/show?__biz=MjM5NzM0MjcyMQ==&appmsgid=10001083&itemidx=2&am ...
- 【Nginx笔记】nginx配置文件具体解释
本文主要对nginx的配置做重点说明,关于nginx的其他基本概念.建议參考官网描写叙述.这里推荐Nginx Beginner's Guide这篇文档.对刚開始学习的人高速认识nginx非常有帮助. ...
- JSP的学习(2)——语法知识一
上一篇<JSP的学习>讲述了JSP的一些基础知识和底层原理,本篇将来学习JSP所需掌握的语法知识等. JSP的语法主要包括以下几个部分的内容: 1) JSP模板元素 2) ...