HDU 4667 Building Fence(2013多校7 1002题 计算几何,凸包,圆和三角形)
Building Fence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 171 Accepted Submission(s): 25
Special Judge
Since the winter is falling, FJ has to build a fence to protect all his cows from hungry wolves, making the territory of cows in the fence. Due to the financial crisis, FJ is currently lack of money, he wants the total length of the fence minimized. So he comes to you, the greatest programmer ever for help. Please note that the part of fence don't have to be a straight line, it can be a curve if necessary.
Each test case begins with two integers N and M(0 ≤ N, M ≤ 50, N + M > 0)which denotes the number of the Friesian and Ayrshire respectively. Then follows N + M lines, each line representing the territory of the cow. Each of the first N lines contains three integers Xi, Yi, Ri(1 ≤ Ri ≤ 500),denotes the coordinates of the circle's centre and radius. Then each of the remaining M lines contains six integers X1i, Y1i, X2i, Y2i, X3i, Y3i, denotes the coordinates of the triangle vertices. The absolute value of the coordinates won't exceed 10000.
4 4 1
0 0 0 2 2 0
Please see the sample picture for more details, the fence is highlighted with red.
标程的正解应该是找圆上的关键点。
两圆两两的切点,和三角形上的点和圆的切点是关键点。
然后所有点求凸包。
如果两个关键点刚好在一个圆上,用圆弧长度代替距离。
我的做法是没有求关键点,直接把圆均匀分成1000个点,然后就水过了。
/* **********************************************
Author : kuangbin
Created Time: 2013/8/13 14:13:06
File Name : F:\2013ACM练习\2013多校7\1002.cpp
*********************************************** */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
using namespace std; const double eps = 1e-;
const double PI = acos(-1.0);
int sgn(double x)
{
if(fabs(x) < eps)return ;
if(x < )return -;
else return ;
}
struct Point
{
double x,y;
int index;
Point(){}
Point(double _x,double _y,int _index)
{
x = _x;y = _y;index = _index;
}
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);
}
}; //*两点间距离
double dist(Point a,Point b)
{
return sqrt((a-b)*(a-b));
} /*
* 求凸包,Graham算法
* 点的编号0~n-1
* 返回凸包结果Stack[0~top-1]为凸包的编号
*/
const int MAXN = ;
Point list[MAXN];
int Stack[MAXN],top;
//相对于list[0]的极角排序
bool _cmp(Point p1,Point p2)
{
double tmp = (p1-list[])^(p2-list[]);
if(sgn(tmp) > )return true;
else if(sgn(tmp) == && sgn(dist(p1,list[]) - dist(p2,list[])) <= )
return true;
else return false;
}
void Graham(int n)
{
Point p0;
int k = ;
p0 = list[];
//找最下边的一个点
for(int i = ;i < n;i++)
{
if( (p0.y > list[i].y) || (p0.y == list[i].y && p0.x > list[i].x) )
{
p0 = list[i];
k = i;
}
}
swap(list[k],list[]);
sort(list+,list+n,_cmp);
if(n == )
{
top = ;
Stack[] = ;
return;
}
if(n == )
{
top = ;
Stack[] = ;
Stack[] = ;
return ;
}
Stack[] = ;
Stack[] = ;
top = ;
for(int i = ;i < n;i++)
{
while(top > && sgn((list[Stack[top-]]-list[Stack[top-]])^(list[i]-list[Stack[top-]])) <= )
top--;
Stack[top++] = i;
}
}
const int NUM = ;
int X[],Y[],R[];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int N,M;
while(scanf("%d%d",&N,&M) == )
{ for(int i =;i < N;i++)
{
scanf("%d%d%d",&X[i],&Y[i],&R[i]);
for(int j = ;j < NUM;j++)
{
double tmp = *PI*j/NUM;
list[j+i*NUM] = Point( X[i] + R[i]*cos(tmp),Y[i] + R[i]*sin(tmp),i );
} }
int x,y;
for(int i = ;i < M;i++)
{
scanf("%d%d",&x,&y);
list[N*NUM+i*] = Point(x,y,-);
scanf("%d%d",&x,&y);
list[N*NUM+i*+] = Point(x,y,-);
scanf("%d%d",&x,&y);
list[N*NUM+i*+] = Point(x,y,-);
}
Graham(N*NUM+M*);
double ans = ;
//cout<<top<<endl;
for(int i = ;i < top;i++)
{
int t1 = Stack[i];
int t2 = Stack[(i+)%top];
// cout<<t1<<" "<<t2<<endl;
// printf("%.2lf %.2lf\n",list[t1].x,list[t2].y);
if(list[t1].index != - && list[t2].index == list[t1].index)
{
int tt = list[t1].index;
ans += R[tt]**PI/(NUM);
}
else ans += dist(list[t1],list[t2]);
}
printf("%.5lf\n",ans);
}
return ;
}
HDU 4667 Building Fence(2013多校7 1002题 计算几何,凸包,圆和三角形)的更多相关文章
- HDU 4643 GSM (2013多校5 1001题 计算几何)
GSM Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submiss ...
- HDU 4667 Building Fence(求凸包的周长)
A - Building Fence Time Limit:1000MS Memory Limit:65535KB 64bit IO Format:%I64d & %I64u ...
- HDU 4705 Y (2013多校10,1010题,简单树形DP)
Y Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submiss ...
- HDU 4704 Sum (2013多校10,1009题)
Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submi ...
- HDU 4699 Editor (2013多校10,1004题)
Editor Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Su ...
- HDU 4696 Answers (2013多校10,1001题 )
Answers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total S ...
- HDU 4678 Mine (2013多校8 1003题 博弈)
Mine Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submis ...
- HDU 4681 String(2013多校8 1006题 DP)
String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Subm ...
- HDU 4666 Hyperspace (2013多校7 1001题 最远曼哈顿距离)
Hyperspace Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
随机推荐
- easyui datagrid 去掉 全选checkbox
在加载 表格的时候添加事件:onLoadSuccess 在事件中写入下面句,用空代替原有HTML 达到取消效果. $(".datagrid-header-check").html( ...
- Spring 控制台运行及RestTemplate实现Eurka负载均衡
spring使用控制台运行方式 spring.main.web-application-type=none新老版本的配置有点差异 Maven的modules只是实现了一个顺序编译,一次多个项目一起生成 ...
- C# Winform频繁刷新导致界面闪烁解决方法
C#Winform频繁刷新导致界面闪烁解决方法 一.通过对窗体和控件使用双缓冲来减少图形闪烁(当绘制图片时出现闪烁时,使用双缓冲) 对于大多数应用程序,.NET Framework 提供的默认双缓冲将 ...
- Delphi 中的自动释放策略
来自万一老师的博客:http://www.cnblogs.com/del/archive/2011/12/21/2295794.html ------------------------------- ...
- C语言俄罗斯方块
#include <windows.h> #include <stdio.h> #include <time.h> #include <conio.h> ...
- 洛谷P1554 梦中的统计 题解
题目传送门 这道题暴力又让我过了...数据真的很水(luogu) 暴力枚举n~m的每个数,再统计一次,交付评测...AC #include<bits/stdc++.h> using nam ...
- 洛谷P1634 禽兽的传染病 题解
题目传送门 最近都在刷红色的水题... 这道题因为是不断地传染,所以直接求幂次方就好啦... 但是一测样例WA了... 原来x初始需要加1... 提交评测WA了... 原来要开long long .. ...
- iis应用池内存溢出卡死优化
1.修改回收阀值memoryLimit 在ASP.NET Web服务器上,ASP.NET所能够用到的内存,通常不会等同于所有的内存数量.在machine.config(C:/WINDOWS/Micro ...
- centos7.5 ab压力测试安装和swoole压力测试
Apache Benchmark(简称ab) 是Apache安装包中自带的压力测试工具 ,简单易用 1.ab安装 yum -y install httpd-tools 2.ab参数详解,传送门:htt ...
- 【Spark亚太研究院系列丛书】Spark实战高手之路-第3章Spark架构设计与编程模型第3节:Spark架构设计(2)
三,深入RDD RDD本身是一个抽象类,具有很多具体的实现子类: RDD都会基于Partition进行计算: 默认的Partitioner如下所示: 其中HashPartitioner的文档说明如下: ...