uva1084
状压dp+凸包
并没有看出来凸包的性质
首先答案一定在凸包上,然后每个凸包的角加起来是一个圆,那么就相当于凸包周长加一个圆了。然后预处理,再状压dp计算即可。
#include<bits/stdc++.h>
using namespace std;
const int N = ;
const double pi = acos(-);
struct points {
double x, y;
bool friend operator < (points A, points B)
{
return A.x == B.x ? A.y < B.y : A.x < B.x;
}
} point[N * ], p[N * ];
int n, m, cnt, top, kase;
double dp[ << N], d[ << N];
int st[N * ];
double cross(points x, points y, points z)
{
return (x.x - z.x) * (y.y - z.y) - (x.y - z.y) * (y.x - z.x);
}
double dis(points x, points y)
{
return sqrt((x.x - y.x) * (x.x - y.x) + (x.y - y.y) * (x.y - y.y));
}
double graham()
{
double ret = ;
top = ;
for(int i = ; i <= cnt; ++i)
{
while(top > && cross(p[i], p[st[top]], p[st[top - ]]) >= ) --top;
st[++top] = i;
}
int lim = top;
for(int i = cnt - ; i; --i)
{
while(top > lim && cross(p[i], p[st[top]], p[st[top - ]]) >= ) --top;
st[++top] = i;
}
for(int i = ; i < top; ++i) ret += dis(p[st[i]], p[st[i + ]]);
return ret;
}
int main()
{
while(scanf("%d%d", &n, &m))
{
if(!n && !m) break;
for(int i = ; i < n; ++i) scanf("%lf%lf", &point[i].x, &point[i].y);
sort(point, point + n);
for(int i = ; i < ( << n); ++i)
{
cnt = ;
for(int j = ; j < n; ++j) if(i & ( << j))
p[++cnt] = point[j];
dp[i] = graham() + * m * pi;
}
for(int i = ; i < ( << n); ++i)
for(int S = i; S; S = (S - ) & i)
dp[i] = min(dp[i], dp[S] + dp[i ^ S]);
printf("Case %d: length = %.2f\n", ++kase, dp[( << n) - ]);
}
return ;
}
uva1084的更多相关文章
随机推荐
- dubbo之优雅停机
优雅停机 Dubbo 是通过 JDK 的 ShutdownHook 来完成优雅停机的,所以如果用户使用 kill -9 PID 等强制关闭指令,是不会执行优雅停机的,只有通过 kill PID 时,才 ...
- 注释及Scriptlet
1.显式注释 <!--xxxxxx-->,在正常页面上也看不出来,右键鼠标查看源代码可以看到 2.隐式注释 //xxxxx /*xxxxxx*/ <%--xxxxxxx--> ...
- Caffe2:python -m caffe2.python.operator_test.relu_op_test
1. 进行语句测试时候,出现问题, 设置环境变量CUDA_VISIBLE_DEVICES 参考: cuda设置指定可见方法 在/etc/profile文件或者-/.bashrc末尾添加以下行: exp ...
- (转)分布式文件存储FastDFS(五)FastDFS常用命令总结
http://blog.csdn.net/xingjiarong/article/details/50561471 1.启动FastDFS tracker: /usr/local/bin/fdfs_t ...
- iOS crash log 解析 symbol address = stack address - slide 运行时获取slide的api 利用dwarfdump从dsym文件中得到symbol
概述: 为什么 crash log 内 Exception Backtrace 部分的地址(stack address)不能从 dsym 文件中查出对应的代码? 因为 ASLR(Address spa ...
- 28 I/O限制的异步操作
28.2 C#的异步函数 private static async Task<string> IssueClientRequestAsync(string serverName, stri ...
- JS练习:表格全选与全不选
代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title ...
- 39.date hitogram基础知识
主要知识点: date hitogram之统计每月电视销量 上一节讲到histogram,他是以数值进行分组.本节讲到以日期进行bucket分组操作,也就是说把连续的日期变成离散的日期区间,然 ...
- BZOJ 2501 [usaco2010 Oct]Soda Machine
[题意概述] 给出一个[0,1,000,000,000]的整数数轴,刚开始每个位置都为0,有n个区间加操作,最后询问数轴上最大的数是多少. [题解] 我写的是离散化后线段树维护区间最值. 其实貌似不用 ...
- 4 pandas模块,Series类
对gtx图像进行操作,使用numpy知识 如果让gtx这张图片在竖直方向上进行颠倒. 如果让gtx这张图片左右颠倒呢? 如果水平和竖直方向都要颠倒呢? 如果需要将gtx的颜色改变一下呢 ...