hdu 3264 Open-air shopping malls(几何)
2015-11-09 20:24
447 查看
题目链接:hdu 3264 Open-air shopping malls
解题思路
圆与圆面积交代码
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const double pi = 4 * atan(1.0); const double eps = 1e-8; inline int dcmp (double x) { if (fabs(x) < eps) return 0; else return x < 0 ? -1 : 1; } struct Point { double x, y; Point (double x = 0, double y = 0): x(x), y(y) {} void read () { scanf("%lf%lf", &x, &y); } Point operator - (const Point& u) { return Point(x - u.x, y - u.y); } }; typedef Point Vector; double getDot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; } double getLength (Vector a) { return sqrt(getDot(a,a)); } double getAngle (double a, double b, double c) { return acos((a*a+b*b-c*c) / (2*a*b)); } struct Circle { Point o; double r; Circle () {} Circle (Point o, double r = 0): o(o), r(r) {} void read () { o.read(), scanf("%lf", &r); } Point point(double rad) { return Point(o.x + cos(rad)*r, o.y + sin(rad)*r); } double getArea (double rad) { return rad * r * r / 2; } }; double getPublicAreaCircleToCircle(Circle a, Circle b) { double dis = getLength(a.o - b.o); if (dcmp(dis-a.r-b.r) >= 0) return 0; if (dis <= fabs(a.r - b.r)) { return min(a.getArea(2*pi), b.getArea(2*pi)); } double ang1 = getAngle(a.r, dis, b.r); double ang2 = getAngle(b.r, dis, a.r); double ret = ang1 * a.r * a.r + ang2 * b.r * b.r - dis * a.r * sin(ang1); return ret; } const double inf = 0x3f3f3f3f; int N; Circle C[30]; bool judge(Circle O) { for (int i = 1; i <= N; i++) { if (getPublicAreaCircleToCircle(O, C[i]) < C[i].getArea(pi)) return false; } return true; } double solve (Point p) { double l = 0, r = inf; for (int i = 0; i < 100; i++) { double mid = (l + r) / 2; if (judge(Circle(p, mid))) r = mid; else l = mid; } return l; } int main () { int cas; scanf("%d", &cas); while (cas--) { scanf("%d", &N); for (int i = 1; i <= N; i++) C[i].read(); double ans = inf; for (int i = 1; i <= N; i++) ans = min(ans, solve(C[i].o)); printf("%.4lf\n", ans); } return 0; }
相关文章推荐
- hdu4770 Lights Against Dudely
- Gradle project sync failed. Please fix your project and try again.
- 正确使用Block避免Cycle Retain和Crash
- Scala初学者学习资料:main(String[])
- 运行Scala应用 Main方法
- .NET 4.0 使用 asyn await
- 父进程等待子进程结束 waitpid wait
- Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON
- git常见错误failed to push some refs to
- NovaException: Unexpected vif_type=binding_failed
- LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)
- 重新启动SNMP服务解决监控AIX系统问题
- Referenced file contains errors 解决方法 (转载地址:http://blog.sina.com.cn/s/blog_6a6b141001011xhn.html)
- Package should contain a content type part [M1.13]
- IntelliJ IDEA 官方网站 http://www.jetbrains.com/idea/
- wait sleep区别
- Goldengate 源端 dump进程无法启动报;scoket buffer size set to xxx connect failed to targetIP:7819,error
- mybtais 映射文件参数简写
- jetbrain kotlin试用笔记
- ADS编译问题