POJ 3831 & HDU 3264 Open-air shopping malls(几何)
题目链接:
POJ: id=3831" target="_blank">http://poj.org/problem?id=3831
HDU:http://acm.hdu.edu.cn/showproblem.php?pid=3264
Description
Unfortunately, the climate has changed little by little and now rainy days seriously affected the operation of open-air shopping malls -- it's obvious that nobody will have a good mood when shopping in the rain. In order to change this situation, the manager
of these open-air shopping malls would like to build a giant umbrella to solve this problem.
These shopping malls can be considered as different circles. It is guaranteed that these circles will not intersect with each other and no circles will be contained in another one. The giant umbrella is also a circle. Due to some technical reasons, the center
of the umbrella must coincide with the center of a shopping mall. Furthermore, a fine survey shows that for any mall, covering half of its area is enough for people to seek shelter from the rain, so the task is to decide the minimum radius of the giant umbrella
so that for every shopping mall, the umbrella can cover at least half area of the mall.
Input
The first line of the input contains one integer T (1 <= T <= 10), which is the number of test cases. For each test case, there is one integer N (1 <= N <= 20) in the first line, representing the number of shopping malls.
The following N lines each contain three integers X,Y,R, representing that the mall has a shape of a circle with radius R and its center is positioned at (X, Y). X and Y are in the range of [-10000,10000] and R is a positive integer less than 2000.
Output
Sample Input
1
2
0 0 1
2 0 1
Sample Output
2.0822
Source
题意:
给出一些圆,选择当中一个圆的圆心为圆心。然后画一个大圆。要求大圆最少覆盖每一个圆的一半面积。求最小面积。
代码例如以下:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm> using namespace std;
const double eps = 1e-8;
const double PI = acos(-1.0); int sgn(double x)
{
if(fabs(x) < eps) return 0;
if(x < 0) return - 1;
else return 1;
}
struct Point
{
double x, y, r;
Point() {}
Point(double _x, double _y)
{
x = _x;
y = _y;
}
Point operator -( const Point &b) const
{
return Point(x - b. x, y - b. y);
}
//叉积
double operator ^ (const Point &b) const
{
return x*b. y - y*b. x;
}
//点积
double operator * (const Point &b) const
{
return x*b. x + y*b. y;
}
//绕原点旋转角度B(弧度值),后x,y的变化
void transXY(double B)
{
double tx = x,ty = y;
x = tx* cos(B) - ty*sin(B);
y = tx* sin(B) + ty*cos(B);
}
};
Point p[47]; //*两点间距离
double dist( Point a, Point b)
{
return sqrt((a-b)*(a- b));
}
//两个圆的公共部分面积
double Area_of_overlap(Point c1, double r1, Point c2, double r2)
{
double d = dist(c1,c2);
if(r1 + r2 < d + eps) return 0;
if(d < fabs(r1 - r2) + eps)
{
double r = min(r1,r2);
return PI*r*r;
}
double x = (d*d + r1*r1 - r2*r2)/(2*d);
double t1 = acos(x / r1);
double t2 = acos((d - x)/r2);
return r1*r1*t1 + r2*r2*t2 - d*r1*sin(t1);
} int main()
{
double x1, y1, r1, x2, y2, r2;
int t;
int n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i = 0; i < n; i++)
{
scanf("%lf %lf %lf",&p[i].x,&p[i].y,&p[i].r);
}
double ans = 999999;
double l, r, mid;
for(int i = 0; i < n; i++) //枚举圆心
{
l = 0;
r = 35000.0;//二分
while(r-l > eps)//能找到
{
mid = (l+r)/2.0;
int flag = 0;
for(int j = 0; j < n; j++) // 每一个点
{
if(Area_of_overlap(p[i],mid,p[j],p[j].r)<p[j].r*p[j].r*PI/2.0)
{
flag = 1;//太小
break;
}
}
if(flag)
l = mid;
else
r = mid;
}
if(l < ans)
ans = l;
}
printf("%.4lf\n",ans);
}
return 0;
}
POJ 3831 & HDU 3264 Open-air shopping malls(几何)的更多相关文章
- HDU 3264/POJ 3831 Open-air shopping malls(计算几何+二分)(2009 Asia Ningbo Regional)
Description The city of M is a famous shopping city and its open-air shopping malls are extremely at ...
- 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 ...
- hdu 3264 Open-air shopping malls(圆相交面积+二分)
Open-air shopping malls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- HDU 3264 区间内的最大最小之差
题目链接:http://poj.org/problem?id=3264 题目大意:在给定一堆牛的数量以及其高度的时候,每次给定一段区间,求这个区间内最高的牛和最矮的牛的高度之差为多少. 可以直接利用R ...
- hdu 3264(枚举+二分+圆的公共面积)
Open-air shopping malls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- hdu 3264 圆的交+二分
Open-air shopping malls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- Open-air shopping malls(二分半径,两元交面积)
http://acm.hdu.edu.cn/showproblem.php?pid=3264 Open-air shopping malls Time Limit: 2000/1000 MS (Jav ...
- UVALive - 6572 Shopping Malls floyd
题目链接: http://acm.hust.edu.cn/vjudge/problem/48416 Shopping Malls Time Limit: 3000MS 问题描述 We want to ...
- HDU 3264 Open-air shopping malls (计算几何-圆相交面积)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3264 题意:给你n个圆,坐标和半径,然后要在这n个圆的圆心画一个大圆,大圆与这n个圆相交的面积必须大于等 ...
随机推荐
- C语言的本质(11)——指针与数组
1.指针数组和数组指针的内存布局 初学者总是分不出指针数组与数组指针的区别.其实很好理解:指针数组:首先它是一个数组,数组的元素都是指针,数组占多少个字节由数组本身决定.它是"储存指针的数组 ...
- poj3673---双重for循环
#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX 15 int main ...
- overfitting
当模型复杂度上升时,可控制参数变多,VC dimension变大, 当VC dimension过大时,虽然Ein很小,但是Eout很大,产生overfitting 比喻:开车 开太快 ...
- Hadoop-Yarn-HA集群搭建(搭建篇)
1.前提条件 我学习过程是一块一块深入的,在把hdfs基本弄懂以及HA成功的情况开始尝试搭建yarn的,建议在搭建前先去看一下转载的原理篇,懂了原理后搭建会很快的,再次强调一下hdfs我默认已经搭建成 ...
- mysql同时update多行
当我们只更新一个字段时的语法如下: UPDATE mytable SET myfield = CASE other_field WHEN 1 THEN 'value' ...
- Android设计中的.9.png
在Android的设计过程中,为了适配不同的手机分辨率,图片大多需要拉伸或者压缩,这样就出现了可以任意调整大小的一种图片格式“.9.png”.这种图片是用于Android开发的一种特殊的图片格式,它的 ...
- sctf pwn200
题目给出了pwn200和libc.so.使用IDA查看程序,发现逻辑很简单. 使用checksec查看pwn200的安全属性,如下图: 发现NX enabled,No PIE. 在第一次读(0x080 ...
- JAVA责任链设计模式
<JAVA与模式>之责任链模式 在阎宏博士的<JAVA与模式>一书中开头是这样描述责任链(Chain of Responsibility)模式的: 责任链模式是一种对象的行为模 ...
- 说说VS 2015 RC最新开发工具的体验
有两个我感觉是提高效率的地方: 1.智能提示的改进,鼠标只要移动到代码上面的类型.字段,就会显示相应的提示,这大大提高我们开发时候需要按F12才能看到定义的内容.下面上图,给大家形象化: 2.管理Nu ...
- ASP.NET不通过添加web引用的方式调用web service接口
尊重原著作:本文转载自http://bbs.csdn.net/topics/360223969 创建方法 //动态调用web服务 public static object InvokeWebSer(s ...