hdu 1077 (圆交)
我们可以知道,当这个单位圆可以覆盖到最多的点的时候,必定最少有两个点位于这个圆的圆周上,于是就有网上众多的O(N^3)的枚举两个在圆上的点的暴搜做法。
然而这题是可以用圆交来做的。
我们以一条鱼的位置作为圆心,半径为1的圆的周围随便找一个点都能把这条鱼抓到。这时,我们可以做出很多个这样的圆,半径都为1。
然后,求一下这些圆的交集,叠起来的最高层数就是最多能获得的鱼的数目。
这里的圆交不需要实现求面积这部分,于是只需要离散一下交点就行了。
1y。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath> using namespace std; const double EPS = 1e-;
const double PI = acos(-1.0);
inline int sgn(double x) { return (x > EPS) - (x < -EPS);}
template<class T> T sqr(T x) { return x * x;}
typedef pair<double, double> Point;
#define x first
#define y second Point operator + (Point a, Point b) { return Point(a.x + b.x, a.y + b.y);}
Point operator - (Point a, Point b) { return Point(a.x - b.x, a.y - b.y);}
Point operator * (Point a, double p) { return Point(a.x * p, a.y * p);}
Point operator * (double p, Point a) { return Point(a.x * p, a.y * p);}
Point operator / (Point a, double p) { return Point(a.x / p, a.y / p);} inline double cross(Point a, Point b) { return a.x * b.y - a.y * b.x;}
inline double dot(Point a, Point b) { return a.x * b.x + a.y * b.y;}
inline double veclen(Point a) { return sqrt(dot(a, a));}
inline double angle(Point a) { return atan2(a.y, a.x);}
inline Point vecunit(Point a) { return a / veclen(a);}
inline Point normal(Point a) { return Point(-a.y, a.x) / veclen(a);} struct Line {
Point s, t;
Line() {}
Line(Point s, Point t) : s(s), t(t) {}
Point vec() { return t - s;}
Point point(double p) { return s + vec() * p;}
} ;
inline Point llint(Line a, Line b) { return a.point(cross(b.vec(), a.s - b.s) / cross(a.vec(), b.vec()));} struct Circle {
Point c;
double r;
Circle() {}
Circle(Point c, double r) : c(c), r(r) {}
Point point(double p) { return c + r * Point(cos(p), sin(p));}
bool in(Point p) { return sgn(veclen(p - c) - r) < ;}
} ; const double R = 1000.0;
const int N = ;
int n;
Circle cir[N]; void input() {
cin >> n;
for (int i = ; i < n; i++) {
cin >> cir[i].c.x >> cir[i].c.y;
cir[i].c = cir[i].c * R;
cir[i].r = R;
}
} bool ccint(int _a, int _b, double *sol) {
Circle a = cir[_a], b = cir[_b];
double d = veclen(a.c - b.c), dr = fabs(a.r - b.r);
if (sgn(d - a.r - b.r) > ) return ;
if (sgn(dr - d) >= ) {
if (a.r < b.r || sgn(a.r - b.r) == && _a < _b) {
sol[] = -PI;
sol[] = PI;
return ;
}
return ;
}
double ang = angle(b.c - a.c);
double da = acos(fabs(sqr(a.r) + sqr(d) - sqr(b.r)) / ( * a.r * d));
sol[] = ang - da;
sol[] = ang + da;
return ;
} typedef pair<double, int> Event;
Event ev[N << ];
bool cmp(Event a, Event b) {
if (sgn(a.x - b.x)) return a.x < b.x;
return a.y > b.y;
} int cal(int id) {
int tt = ;
double _[];
for (int i = ; i < n; i++) {
if (i == id) continue;
if (ccint(id, i, _)) {
if (_[] < -PI) {
ev[tt++] = Event(_[] + * PI, );
ev[tt++] = Event(PI, -);
ev[tt++] = Event(-PI, );
ev[tt++] = Event(_[], -);
} else if (_[] > PI) {
ev[tt++] = Event(_[], );
ev[tt++] = Event(PI, -);
ev[tt++] = Event(-PI, );
ev[tt++] = Event(_[] - * PI, -);
} else {
ev[tt++] = Event(_[], );
ev[tt++] = Event(_[], -);
}
}
}
int cnt = , mx = ;
sort(ev, ev + tt, cmp);
for (int i = ; i < tt; i++) {
cnt += ev[i].y;
mx = max(mx, cnt);
}
return mx;
} int work() {
int mx = ;
for (int i = ; i < n; i++) mx = max(mx, cal(i));
return mx;
} int main() {
//freopen("in", "r", stdin);
ios::sync_with_stdio();
cout << setiosflags(ios::fixed) << setprecision();
int _;
cin >> _;
while (_--) {
input();
cout << work() << endl;
}
return ;
}
——written by Lyon
hdu 1077 (圆交)的更多相关文章
- HDU 3467 Song of the Siren(圆交)
Problem Description In the unimaginable popular DotA game, a hero Naga Siren, also known as Slithice ...
- 计算几何(容斥原理,圆交):HDU 5120 Intersection
Matt is a big fan of logo design. Recently he falls in love with logo made up by rings. The followin ...
- HDU 3264 Open-air shopping malls ——(二分+圆交)
纯粹是为了改进牛吃草里的两圆交模板= =. 代码如下: #include <stdio.h> #include <algorithm> #include <string. ...
- Intersection(HDU5120 + 圆交面积)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5120 题目: 题意: 求两个圆环相交的面积. 思路: 两个大圆面积交-2×大圆与小圆面积交+两小圆面 ...
- CF 337D 求圆交
题目链接:http://codeforces.com/problemset/problem/337/D 题意:就是一棵树上,有一些点被来自东方的神秘力量影响的,力量影响范围是d,为可能的力量源有几个. ...
- hdu 5700区间交(线段树)
区间交 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...
- HDU 3511 圆扫描线
找最深的圆,输出层数 类似POJ 2932的做法 圆扫描线即可.这里要记录各个圆的层数,所以多加一个维护编号的就行了. /** @Date : 2017-10-18 18:16:52 * @FileN ...
- hdu 6010 路径交
hdu 6010 路径交(lca + 线段树) 题意: 给出一棵大小为\(n\)的树和\(m\)条路径,求第\(L\)条路径到第\(R\)条路径的交的路径的长度 思路: 本题的关键就是求路径交 假设存 ...
- hdu 3264 圆的交+二分
Open-air shopping malls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
随机推荐
- Hibernate中的Query
//1:创建query对象,方法里面写hql语句 Query query = session.createQuery("from User"); //2:利用query对象中的方法 ...
- Cannot allocate memory for the buffer pool
优化了一通,启动不了 直接上日志 innodb_buffer_pool_size”.”key_buffer_size” 的大小设置,适当的调大内存分配,减小,然后保存配置文件,重新尝试启mysql 成 ...
- Anngular.js的大致了解
只要出发事件 这个事件会刷新DOM节点,去重新渲染DOM节点(把dom擦掉重新画) 浪费内存 浪费效率所以使用Angular.js -懒查找 不涉及渲染 效率最高 展现效率 比原声使用两个事件互相监听 ...
- 问题解决:listview多次调用addHeaderView和addFooterView
情景: 有两个分类,每个分类下的数据用listview显示,分类1需要显示头视图和尾视图,分类2不要显示头视图和尾视图 .两个分类可以来回切换. 实现的步骤: 1. addHeaderView . a ...
- SEO优化步骤
SEO技术并不是简单的几个建议,而是一项需要足够耐心和细致的脑力劳动.大体上,SEO优化主要分为8小步: 1.关键词分析(也叫关键词定位) 这是进行SEO优化最重要的一环,关键词分析包括:关键词关注量 ...
- Mysql查询优化-DB篇
本文重点从数据库本身角度,硬件和环境的优化不在本文范围内 1. 使用索引(Index All Columns Used in 'where', 'order by', and 'group by' C ...
- 简单介绍几个CSSReset的方法
对于小型的网站来说,用这个并不会带来大的资源浪费,但如果是像Yahoo这种架构非常大的网站,必须要有选择地进行CSS重设,以减 少资源浪费. 正在使用CSS的你,用过CSS Reset吗?当然,或许你 ...
- linux系统搭建zookeeper集群
转载至:https://blog.csdn.net/weixin_38111957/article/details/82927878 一.引言 今天咱们就来搭建一下zookeeper集群,当然搭建集群 ...
- NFS客户端挂载目录后无写入权限的解决方案
转载至:https://blog.csdn.net/younger_china/article/details/52089337 在客户机通过 mount -o rw -t nfs 192.168.1 ...
- PHP 中的 curl 函数发送 Post 请求应该注意的几点
public function http_request( $url, $post = '', $timeout = 5 ){ if( empty( $url ) ){return ;}$ch = c ...