一次放下n个圆

问最终可见的圆的数量

应该是比较经典的问题吧

考虑一个圆与其他每个圆的交点O(n)个

将其割成了O(n)条弧

那么看每条弧的中点 分别向内向外调动eps这个点 则最上面的覆盖这个点的圆可见O(n)

总时间复杂度O(n ** 3)

怕炸精度,代码基本抄的rjl的

 #include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector> using namespace std; typedef double data_type; const data_type eps = * 1e-;
int dcmp(const data_type& x) {
if(fabs(x) < ) return ; return x < ? - : ;
} const data_type pi = acos(-1.0), dpi = * acos(-1.0); double NormalizeAngle(double rad) {
return rad - dpi * floor(rad / dpi);
} typedef const struct Point& Point_cr;
typedef struct Point {
data_type x, y;
Point() {}
Point(data_type x, data_type y) : x(x), y(y) {}
Point operator + (Point_cr rhs) const {
return Point(x + rhs.x, y + rhs.y);
}
Point operator - (Point_cr rhs) const {
return Point(x - rhs.x, y - rhs.y);
}
Point operator * (data_type k) const {
return Point(x * k, y * k);
}
Point operator / (double k) const {
return Point(x / k, y / k);
}
double length() const {
return hypot(x, y);
}
double angle() const {
return atan2(y, x);
}
}Vector; double Dot(const Vector& v1, const Vector& v2) {
return v1.x * v2.x + v1.y * v2.y;
} double length(const Vector& v) {
return sqrt(Dot(v, v));
} typedef const Vector& Vector_cr;
void CircleCircleIntersection(Point_cr c1, double r1, Point c2, double r2, vector<double> &rad) {
double d = (c1 - c2).length();
if(dcmp(d) == ) return;
if(dcmp(r1 + r2 - d) < ) return;
if(dcmp(fabs(r1 - r2) - d) > ) return;
double a = (c2 - c1).angle();
double da = acos((r1 * r1 + d * d - r2 * r2) / ( * r1 * d));
rad.push_back(NormalizeAngle(a + da));
rad.push_back(NormalizeAngle(a - da));
} const int N = + ;
int n;
Point centre[N];
double radius[N];
bool vis[N]; int topmost(Point p) {
for(int i = n - ; i >= ; i--) {
if((centre[i] - p).length() < radius[i]) return i;
}
return -;
} int main() {
#ifdef DEBUG
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif while(scanf("%d", &n) == && n) {
for(int i = ; i < n; i++) {
double x, y, r;
scanf("%lf%lf%lf", &x, &y, &r);
centre[i] = Point(x, y);
radius[i] = r;
}
memset(vis, , sizeof vis);
for(int i = ; i < n; i++) {
vector<double> rad;
rad.push_back();
rad.push_back(dpi); for(int j = ; j < n; j++) {
CircleCircleIntersection(centre[i], radius[i], centre[j], radius[j], rad);
} sort(rad.begin(), rad.end()); for(unsigned j = ; j < rad.size(); j++) {
double mid = (rad[j] + rad[j+]) / 2.0;
for(int side = -; side <= ; side += ) {
double r2 = radius[i] - side * eps;
int t = topmost(Point(centre[i].x + cos(mid) * r2, centre[i].y + sin(mid) * r2));
if(t >= ) vis[t] = ;
}
}
}
int ans = ;
for(int i = ; i < n; i++) if(vis[i]) {
ans++;
}
printf("%d\n", ans);
} return ;
}

UVaLive2572 poj1418 UVa1308 Viva Confetti的更多相关文章

  1. poj1418 Viva Confetti 判断圆是否可见

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Viva Confetti Time Limit: 1000MS   Memory ...

  2. poj 1418 Viva Confetti

    Viva Confetti Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1025   Accepted: 422 Desc ...

  3. ZOJ 1696 Viva Confetti 计算几何

    计算几何:按顺序给n个圆覆盖.问最后能够有几个圆被看见.. . 对每一个圆求和其它圆的交点,每两个交点之间就是可能被看到的圆弧,取圆弧的中点,往外扩展一点或者往里缩一点,从上往下推断有没有圆能够盖住这 ...

  4. uva 2572 Viva Confetti

    思路: 小圆面是由小圆弧围成.那么找出每条小圆弧,如果小圆弧,在小圆弧中点上下左右进行微小位移的所得的点一定在一个小圆面内. 找到最后覆盖这个小点的圆一定是可见的. 圆上的点按照相邻依次排序的关键量为 ...

  5. uva 1308 - Viva Confetti

    这个题目的方法是将圆盘分成一个个圆环,然后判断这些圆环是否被上面的圆覆盖: 如果这个圆的圆周上的圆弧都被上面的覆盖,暂时把它标记为不可见: 然后如果他的头上有个圆,他有个圆弧可见,那么他自己本身可见, ...

  6. LA2572 Viva Confetti

    题意 PDF 分析 两两圆求交点,对每个圆弧按半径抖动. 时间复杂度\(O(T n^2)\) 代码 #include<iostream> #include<cstdio> #i ...

  7. [GodLove]Wine93 Tarining Round #9

    比赛链接: http://vjudge.net/contest/view.action?cid=48069#overview 题目来源: lrj训练指南---二维几何计算   ID Title Pro ...

  8. POJ 1418 基本操作和圆 离散弧

    Viva Confetti Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 761   Accepted: 319 Descr ...

  9. Thesis Viva checklist

    This list gives you suggestions helpful in preparing to defend your thesis: I know my thesis thoroug ...

随机推荐

  1. C#程序中:如何修改xml文件中的节点(数据)

    要想在web等程序中实现动态的数据内容给新(如网页中的Flash),不会更新xml文件中的节点(数据)是远远不够的,今天在这里说一个简单的xml文件的更新,方法比较基础,很适合初学者看的,保证一看就懂 ...

  2. frameset标签代码实现网站跳转

    js代码1: document.writeln("<frameset rows=\"0, *\">"); document.writeln(&quo ...

  3. VB版本查询快递单号源码

    能查询各大快递单号,包括申通快递,圆通快递,韵达快递等国内超过90家以上快递单号查询, 如果想快速搭建一个快递单号查询站我推荐这个,这是地址www.aikuaidi.cn,我分享一个VB Functi ...

  4. execute、executeUpdate、executeQuery三者的区别及返回值

    一.boolean execute(String sql)允许执行查询语句.更新语句.DDL语句.返回值为true时,表示执行的是查询语句,可以通过getResultSet方法获取结果:返回值为fal ...

  5. 把一个string串的所有小写字母转成大写字母的例子来看看看全局函数的使用

    今天写了一个小例子,把字符串里面的所有小写字母全部转换成大写字母http://blog.csdn.net/yasaken/article/details/7303903 1 #include &quo ...

  6. Python如何进行cross validation training

    以4-fold validation training为例 (1) 给定数据集data和标签集label 样本个数为 sampNum = len(data) (2) 将给定的所有examples分为1 ...

  7. 使用spring的jdbcTemplate-----用JDBC模板查询数据库

    JdbcTemplate类声明了几个重载的query()模板方法来控制整个查询过程,就像进行更新数据操作一样,通过实现PreparedStatementCreator和PreparedStatemen ...

  8. [HDOJ - 5208] Where is Bob 【DFS+按位贪心】

    题目链接:HDOJ - 5208 题目分析 使用按位贪心的思想,即从高位向低位枚举,尽量使这一位的答案为 1 . 我们使用 DFS ,每次就是对于  [l1, r1] [l2, r2] x  进行处理 ...

  9. HTML Imports

    为什么需要导入? 先想想你在 web 上是如何加载不同类型的资源.对于 JS,我们有 <script src>.<link rel="stylesheet"> ...

  10. 《Effective C++》内存管理

    如果global new-hander没有成功配置,会抛出一个std::bad_alloc的exception. #include<iostream> #include<new> ...