Gym-101915B Ali and Wi-Fi 计算几何 求两圆交点
题意:给你n个圆,每个圆有一个权值,你可以选择一个点,可以获得覆盖这个点的圆中,权值最大的m个的权值,问最多权值是多少
题解:好像是叙利亚的题....我们画画图就知道,我们要找的就是圆与圆交的那部分里面的点,我们再仔细看看,
2个圆的交点一定在啊!
别急啊,两个圆包含了,都是交点,取哪呢?当然小圆圆心就够了啊(圆又不多,写的时候直接把所有的圆心都丢进去了)
然后枚举判断每个点有没有被在m个圆中就行了,这里维护最大的m个,用个堆就好了
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
const ld eps = 1e-;
int dcmp(ld x)
{
if(fabs(x) < eps) return ;
return x < ? - : ;
}
ld sqr(ld x) { return x * x; }
struct Point
{
ld x, y;
Point(ld x = , ld y = ):x(x), y(y) {}
};
Point operator - (const Point& A, const Point& B)
{
return Point(A.x - B.x, A.y - B.y);
}
bool operator == (const Point& A, const Point& B)
{
return dcmp(A.x - B.x) == && dcmp(A.y - B.x) == ;
}
ld Dot(const Point& A, const Point& B)
{
return A.x * B.x + A.y * B.y;
}
ld dis(Point a,Point b)
{
return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));
}
ld Length(const Point& A) { return sqrt(Dot(A, A)); }
ld angle(Point v) { return atan2(v.y, v.x); }
struct Circle
{
Point c;
ld r,v;
Circle() {}
Circle(Point c, ld r):c(c), r(r) {}
inline Point point(double a)
{
return Point(c.x+cos(a)*r, c.y+sin(a)*r);
}
}a[];
int getCircleCircleIntersection(Circle C1, Circle C2,Point &t1,Point &t2)
{
ld d = Length(C1.c - C2.c);
if(dcmp(d) == )
{
if(dcmp(C1.r - C2.r) == ) return -;
return ;
}
if(dcmp(C1.r + C2.r - d) < ) return ;
if(dcmp(fabs(C1.r-C2.r) - d) > ) return ;
ld a = angle(C2.c - C1.c);
ld da = acos((C1.r*C1.r + d*d - C2.r*C2.r) / (*C1.r*d));
Point p1 = C1.point(a-da), p2 = C1.point(a+da);
t1=p1;
if(p1 == p2) return ;
t2=p2;
return ;
}
Point jd[];
ld ans,sum;
int n,m,T,tot;
priority_queue<int,vector<int>,greater<int> >q;
int main()
{
scanf("%d",&T);
while (T--)
{
tot=;
ans=;
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++) scanf("%Lf%Lf%Lf%Lf",&a[i].c.x,&a[i].c.y,&a[i].r,&a[i].v);
for (int i=;i<=n;i++)
for (int j=i+;j<=n;j++)
{
Point t1,t2;
int why=getCircleCircleIntersection(a[i],a[j],t1,t2);
if (why==)
{
tot++;
jd[tot]=t1;
}else
if (why==)
{
tot++;jd[tot]=t1;
tot++;jd[tot]=t2;
}
}
for (int i=;i<=n;i++)
{
tot++;
jd[tot]=a[i].c;
}
for (int i=;i<=tot;i++)
{
for (int j=;j<=n;j++)
if (dcmp(dis(jd[i],a[j].c)-a[j].r)<=)
{
q.push(a[j].v);
if ((int)q.size()>m) q.pop();
}
sum=;
while (!q.empty()) sum+=q.top(),q.pop();
ans=max(ans,sum);
}
printf("%.Lf\n",ans);
}
}
Gym-101915B Ali and Wi-Fi 计算几何 求两圆交点的更多相关文章
- POJ 2546 & ZOJ 1597 Circular Area(求两圆相交的面积 模板)
题目链接: POJ:http://poj.org/problem? id=2546 ZOJ:problemId=597" target="_blank">http: ...
- ZOJ 1280 Interesting Lines | 求两直线交点
原题: 求两直线交点 思路借鉴于:http://blog.csdn.net/zxy_snow/article/details/6341282 感谢大佬 #include<cstdio> # ...
- hdu 2857:Mirror and Light(计算几何,点关于直线的对称点,求两线段交点坐标)
Mirror and Light Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu5858 Hard problem(求两圆相交面积)
题目传送门 Hard problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- 求两圆相交部分面积(C++)
已知两圆圆心坐标和半径,求相交部分面积: #include <iostream> using namespace std; #include<cmath> #include&l ...
- UVa 10674 (求两圆公切线) Tangents
题意: 给出两个圆的圆心坐标和半径,求这两个圆的公切线切点的坐标及对应线段长度.若两圆重合,有无数条公切线则输出-1. 输出是按照一定顺序输出的. 分析: 首先情况比较多,要一一判断,不要漏掉. 如果 ...
- Gym-101158J Cover the Polygon with Your Disk 计算几何 求动圆与多边形最大面积交
题面 题意:给出小于10个点形成的凸多边形 和一个半径为r 可以移动的圆 求圆心在何处的面积交最大,面积为多少 题解:三分套三分求出圆心位置,再用圆与多边形面积求交 #include<bits/ ...
- hdu 5120 (求两圆相交的面积
题意:告诉你两个圆环,求圆环相交的面积. /* gyt Live up to every day */ #include<cstdio> #include<cmath> #in ...
- [poj] 1269 [zoj] 1280 Interesting Lines || 求两直线交点
POJ原题 ZOJ原题 多组数据.每次给出四个点,前两个点确定一条直线,后两个点确定一条直线,若平行则输出"NONE",重合输出"LINE",相交输出" ...
随机推荐
- 利用set特性判断list是否存在重复的值
List<String> list2=new ArrayList();//存放很多值的list //根据set不能存储相同的值该特性来判断list2中的值是否重复 HashSet set ...
- (转)基于Metronic的Bootstrap开发框架经验总结(4)--Bootstrap图标的提取和利用
http://www.cnblogs.com/wuhuacong/p/4762924.html 在前面的一篇随笔<基于Metronic的Bootstrap开发框架经验总结(1)-框架总览及菜单模 ...
- Js正则匹配处理时间
<html> <body> <script type="text/javascript"> //将long 型 转换为 日期格式 年-月-日 h ...
- redis得配置及使用
http://www.cnblogs.com/huskyking/p/6004772.html
- PAT_A1108#Finding Average
Source: PAT A 1108 Finding Average (20 分) Description: The basic task is simple: given N real number ...
- PKU 1019 Number Sequence(模拟,思维)
题目 以下思路参考自discuss:http://poj.org/showmessage?message_id=176353 /*我的思路: 1.将长串数分成一个个部分,每个部分是从1到x的无重复的数 ...
- java获取当前日期的前一天,前一月和前一年
核心:使用Calendar的add(int field, int amount)方法 Calendar ca = Calendar.getInstance();//得到一个Calendar的实例 ca ...
- router-link-active 与 router-link-exact-active 区别
我的github:swarz,欢迎给老弟我++星星 router-link-exact-active 是精确匹配规则,即只有当前点击router被匹配 router-link-active 默认是全包 ...
- Linux简单的进度条
echo '进度条' i= bar="" ] do let idx=i% printf "[%-100s][%d%%]\r" "$bar" ...
- 09.正则表达式re-2.complie函数
compile 函数用于编译正则表达式,生成一个 Pattern 对象,它的一般使用形式如下: import re # 将正则表达式编译成 Pattern 对象 pattern = re.compil ...