还没开始写题解我就已经内牛满面了,从晚饭搞到现在,WA得我都快哭了呢

题意:

在DotA中,你现在1V5,但是你的英雄有一个半径为r的眩晕技能,已知敌方五个英雄的坐标,问能否将该技能投放到一个合适的位置,使得对面所有敌人都被眩晕,这样你就有机会能够逃脱。

分析:

对于敌方一个英雄来说,如果技能的投放位置距离他不超过r则满足要求,那么如果要眩晕所有的敌人,可行区域就是以五人为中心的半径为r的圆的相交区域。

现在问题就转化为求五个半径相同的圆的相交部分的面积,如果只有一个点则输出该点。

在求交之前,我们可以先去除

我们将所交区域划分为一个凸多边形和周围若干个弓形。

弓形在两圆相交时便能求出,而且还能求出两圆的交点(注意两个交点p1,p2一定要按照逆时针的顺序,因为叉积有正负),也就是凸多边的顶点,其面积形直接用叉积来计算。

给两个传送门,认真学习一下吧:

http://www.cnblogs.com/oyking/archive/2013/11/14/3424517.html

对于枚举一个圆求与另外四个圆相交区域,是按照极角的区间求交集,详见:

http://hi.baidu.com/aekdycoin/item/7618bee9f473ed3e86d9ded6

五个圆是否交于一点还要另行判断

最后再感慨一下做计算几何说多了都是泪啊

 #include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm> const int maxn = ;
const double eps = 1e-;
const double PI = acos(-1.0); int dcmp(double x)
{ return (x > eps) - (x < -eps); } struct Point
{
double x, y;
Point(double x=, double y=):x(x), y(y) {}
void read() { scanf("%lf%lf", &x, &y); }
};
typedef Point Vector;
Point operator + (const Vector& a, const Vector& b)
{ return Point(a.x+b.x, a.y+b.y); }
Point operator - (const Vector& a, const Vector& b)
{ return Point(a.x-b.x, a.y-b.y); }
Vector operator * (const Vector& a, double p)
{ return Point(a.x*p, a.y*p); }
Vector operator / (const Vector& a, double p)
{ return Point(a.x/p, a.y/p); }
bool operator == (const Point& a, const Point& b)
{ return dcmp(a.x-b.x) == && dcmp(a.y-b.y) == ; } double Dot(const Vector& a, const Vector& b)
{ return a.x*b.x + a.y*b.y; }
double Cross(const Vector& a, const Vector& b)
{ return a.x*b.y - a.y*b.x; }
double Length(const Vector& a)
{ return sqrt(Dot(a, a)); }
Vector unit(const Vector& a)
{ return a / Length(a); }
Vector Normal(const Vector& a)
{
double l = Length(a);
return Vector(-a.y/l, a.x/l);
}
double Angle(const Vector& a)
{ return atan2(a.y, a.x); } Point Rotate(const Point& p, double angle, const Point& o = Point(, ))
{
Vector t = p - o;
t = Vector(t.x*cos(angle)-t.y*sin(angle), t.x*sin(angle)+t.y*cos(angle));
return t + o;
} struct Region
{
double st, ed;
Region(double s=, double e=):st(s), ed(e) {}
}; struct Circle
{
Point c;
double r;
Circle() {}
Circle(Point c, double r):c(c), r(r) {} void read() { c.read(); scanf("%lf", &r); } double area() const { return PI * r * r; } bool contain(const Circle& rhs) const
{ return dcmp(Length(c-rhs.c) + rhs.r - r) <= ; } bool contain(const Point& p) const
{ return dcmp(Length(c-p) - r) <= ; } bool intersect(const Circle& rhs) const
{ return dcmp(Length(c-rhs.c) - r - rhs.r) < ; } bool tangency(const Circle& rhs) const
{ return dcmp(Length(c-rhs.c) - r - rhs.r) == ; } Point get_point(double ang) const
{ return Point(c.x + r * cos(ang), c.y + r * sin(ang)); }
}; void IntersectionPoint(const Circle& c1, const Circle& c2, Point& p1, Point& p2)
{
double d = Length(c1.c - c2.c);
double l = (c1.r*c1.r + d*d - c2.r*c2.r) / ( * d);
double h = sqrt(c1.r*c1.r - l*l);
Point mid = c1.c + unit(c2.c-c1.c) * l;
Vector t = Normal(c2.c - c1.c) * h;
p1 = mid + t;
p2 = mid - t;
} double IntersectionArea(const Circle& c1, const Circle& c2)
{
double area = 0.0;
const Circle& M = c1.r > c2.r ? c1 : c2;
const Circle& N = c1.r > c2.r ? c2 : c1;
double d = Length(c1.c-c2.c); if(d < M.r + N.r && d > M.r - N.r)
{
double Alpha = 2.0 * acos((M.r*M.r + d*d - N.r*N.r) / ( * M.r * d));
double Beta = 2.0 * acos((N.r*N.r + d*d - M.r*M.r) / ( * N.r * d));
area = ( M.r*M.r*(Alpha - sin(Alpha)) + N.r*N.r*(Beta - sin(Beta)) ) / 2.0;
}
else if(d <= M.r - N.r) area = N.area(); return area;
} struct Region_vector
{
int n;
Region v[];
void clear() { n = ; }
void add(const Region& r) { v[n++] = r; }
} *last, *cur; Circle cir[maxn];
bool del[maxn];
double r;
int n = ; bool IsOnlyOnePoint()
{
bool flag = false;
Point t;
for(int i = ; i < n; ++i)
{
for(int j = i + ; j < n; ++j)
{
if(cir[i].tangency(cir[j]))
{
t = (cir[i].c + cir[j].c) / ;
flag = true;
break;
}
}
} if(!flag) return false;
for(int i = ; i < n; ++i)
if(!cir[i].contain(t)) return false; printf("Only the point (%.2f, %.2f) is for victory.\n", t.x, t.y);
return true;
} bool solve()
{
if(IsOnlyOnePoint()) return true;
memset(del, false, sizeof(del)); for(int i = ; i < n; ++i)
for(int j = ; j < n; ++j)
{
if(del[j] || i == j) continue;
if(cir[i].contain(cir[j]))
{
del[i] = true;
break;
}
} double ans = 0.0;
for(int i = ; i < n; ++i)
{
if(del[i]) continue;
last->clear();
Point p1, p2;
for(int j = ; j < n; ++j)
{
if(del[j] || i == j) continue;
if(!cir[i].intersect(cir[j])) return false;
cur->clear();
IntersectionPoint(cir[i], cir[j], p1, p2);
double rs = Angle(p2 - cir[i].c);
double rt = Angle(p1 - cir[i].c);
if(dcmp(rs) < ) rs += * PI;
if(dcmp(rt) < ) rt += * PI;
if(last->n == )
{
if(dcmp(rt - rs) < )
{
cur->add(Region(rs, *PI));
cur->add(Region(, rt));
}
else cur->add(Region(rs, rt));
}
else
{
for(int k = ; k < last->n; ++k)
{
if(dcmp(rt - rs) < )
{
if(dcmp(last->v[k].st-rt) >= && dcmp(last->v[k].ed-rs) <= ) continue;
if(dcmp(last->v[k].st-rt) < ) cur->add(Region(last->v[k].st, std::min(last->v[k].ed, rt)));
if(dcmp(last->v[k].ed-rs) > ) cur->add(Region(std::max(last->v[k].st, rs), last->v[k].ed));
}
else
{
if(dcmp(rt-last->v[k].st <= || dcmp(rs-last->v[k].ed) >= )) continue;
cur->add(Region(std::max(rs, last->v[k].st), std::min(rt, last->v[k].ed)));
}
}
}
std::swap(cur, last);
if(last->n == ) break;
}
for(int j = ; j < last->n; ++j)
{
p1 = cir[i].get_point(last->v[j].st);
p2 = cir[i].get_point(last->v[j].ed);
ans += Cross(p1, p2) / ;
double ang = last->v[j].ed - last->v[j].st;
ans += cir[i].r * cir[i].r * (ang - sin(ang)) / ;
}
} if(dcmp(ans) == ) return false;
printf("The total possible area is %.2f.\n", ans);
return true;
} int main(void)
{
//freopen("3467in.txt", "r", stdin);
last = new Region_vector;
cur = new Region_vector;
while(scanf("%lf", &r) == )
{
Point t;
for(int i = ; i < n; ++i)
{
t.read();
cir[i] = Circle(t, r);
}
if(!solve())
puts("Poor iSea, maybe 2012 is coming!");
} return ;
}

代码君

HDU 3467 (求五个圆相交面积) Song of the Siren的更多相关文章

  1. hdu 3264 09 宁波 现场 E - Open-air shopping malls 计算几何 二分 圆相交面积 难度:1

    Description The city of M is a famous shopping city and its open-air shopping malls are extremely at ...

  2. hdu5858 Hard problem(求两圆相交面积)

    题目传送门 Hard problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  3. hdu 3264 Open-air shopping malls(圆相交面积+二分)

    Open-air shopping malls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  4. HDU 3264 Open-air shopping malls (计算几何-圆相交面积)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3264 题意:给你n个圆,坐标和半径,然后要在这n个圆的圆心画一个大圆,大圆与这n个圆相交的面积必须大于等 ...

  5. [hdu 3264] Open-air shopping malls(二分+两圆相交面积)

    题目大意是:先给你一些圆,你可以任选这些圆中的一个圆点作圆,这个圆的要求是:你画完以后.这个圆要可以覆盖之前给出的每一个圆一半以上的面积,即覆盖1/2以上每一个圆的面积. 比如例子数据,选左边还是选右 ...

  6. java求两个圆相交坐标

    最近由于项目需要,根据两个圆函数求出相交的坐标.实现代码如下,另感谢两圆求交点算法实现Java代码,虽然他所贡献的代码中存在问题,但仍有借鉴意义. 1.两个圆相交的数学求法 在中学数学中我们知道,一个 ...

  7. hdu 5120 Intersection 两个圆的面积交

    Intersection Time Limit: 4000/4000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) P ...

  8. poj3675 求多边形与圆的面积交

    题意:给出多边形的顶点坐标.圆的圆心坐标和半径,求面积交 sol:又是模板题啦= = 注意poj的C++好像认不出hypot函数,要稍微改写一下. hypot(double x,double y):即 ...

  9. poj2546Circular Area(两圆相交面积)

    链接 画图推公式 这两种情况 都可用一种公式算出来 就是两圆都求出圆心角 求出扇形的面积减掉三角形面积 #include <iostream> using namespace std; # ...

随机推荐

  1. C#中Linq查询基本操作

    摘要:本文介绍Linq查询基本操作(查询关键字) - from 子句 - where 子句 - select子句 - group 子句 - into 子句 - orderby 子句 - join 子句 ...

  2. [algothrim]URL相似度计算的思考

    http://www.spongeliu.com/399.html http://in.sdo.com/?p=865

  3. 1515 跳 - Wikioi

    题目描述 Description邪教喜欢在各种各样空间内跳.现在,邪教来到了一个二维平面.在这个平面内,如果邪教当前跳到了(x,y),那么他下一步可以选择跳到以下4个点:(x-1,y), (x+1,y ...

  4. JS实现Web网页打印功能(IE)

    问题描述:     JS实现Web网页打印功能 问题解决:     这里主要使用WebBrowser控件的ExeWB在IE中打印功能的实现 WebBrowser介绍:         WebBrows ...

  5. spoj 274

    离散化   枚举行  扫描横坐标 #include <iostream> #include <cstdio> #include <cstring> #include ...

  6. 微信ios版6.2更新 聊天记录迁移更快捷朋友圈可翻译

    微信iPhone版昨日发布更新,版本号为微信 6.2 for iOS,主要特性有聊天记录迁移.发送图片更快捷.支持朋友圈翻译.手机充值可充流量查余额.可以通过展示二维码来收钱,和ytkah一起来瞧瞧吧 ...

  7. PHP7 扩展之自动化测试

    在安装 PHP7 及各种扩展的过程中,如果你是用源码安装,会注意到在 make 成功之后总会有一句提示:Don't forget to run 'make test'. 这个 make test 就是 ...

  8. CC150 上面重要的题目总结

    第一章 : 全部重要 (1.6, 1.7 Leetcode上有). 1.5 面A碰到 (string compression) 1.7面Z碰到 (set 0) 1.8面Bigfish碰到 (strin ...

  9. Ubuntu Geany中文乱码

    打开Geany,编辑,首选项,文件,选中“使用固定的编码打开非Unicode文件”,缺省编码选择“简体中文GBK)”. 另外,直接把文本文件拖进浏览器也行(前提是你的浏览器使用的是中文,我用的chro ...

  10. 安装ubuntu vi编辑无法正常使用的时候 如方向键变成ABCD

    http://blog.sina.com.cn/s/blog_7e3f6e8f0100vkon.html 在使用ubuntu的时候,发现vi编辑模式下退格键backspace和上下左右光标移动键不能用 ...