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的更多相关文章
随机推荐
- (原创)如何对APP服务端进行压力测试
版权声明:本文为原创文章,转载请先联系并标明出处 APP性能测试分为客户端性能测试和服务端性能测试,客户端的性能测试主要是针对启动快慢.耗电量.耗流量.内存使用等指标进行评估,目前主流的APP客户端性 ...
- 9-4前端vue面试的问题
就没有什么顺序了,肖师傅的一些提问: 1- 配置文件中proxyTable的作用 2-@import '~styles/mixins.styl' ~的作用 3-vue模拟的本地中访问地址的url带有 ...
- Async/await语法糖实现(Generator)
// generator也是一种迭代器(Iterator) 有next方法,并返回一个对象{value:...,done:...} function run(generatorFunction) { ...
- awk 新手入门笔记
转自:http://www.habadog.com/2011/05/22/awk-freshman-handbook/ awk新手入门笔记 @作者 : habadog@邮箱 : habadog1203 ...
- JeePlus 工作流版本 sping mvc oa crm erp java html5 源码
https://shop108220642.taobao.com/search.htm?spm=2013.1.w5002-5297459241.1.mnhAZ5&search=y http:/ ...
- hdu 1584 蜘蛛纸牌
把小的牌放到大的牌上,求最小移动的距离和 DFS遍历所有的可能,把每一张牌与之要移动的牌都进行两层for的循环,注意回溯条件满足立刻break 代码(算法借鉴) #include <bits/s ...
- 爬虫文件存储-1:mysql
1.连接并创建数据库 import pymysql db = pymysql.connect(host='localhost', user='root', password='root', port= ...
- 1、深度学习模型的基本结构——RNN
本系列为深度学习课程笔记,课程网址在http://speech.ee.ntu.edu.tw/~tlkagk/courses_MLDS17.html 深度学习的基本步骤:定义模型-->定义损失函数 ...
- Django——5 自定义过滤器及标签
Django 自定义过滤器 自定义标签 简单标签 包含标签 自定义过滤器 自定义过滤器就是一个带有一个或两个参数的Python 函数: - (输入的)变量的值 —— 不一定是字符串形式. - 参数的值 ...
- 【LeetCode Weekly Contest 26 Q2】Longest Uncommon Subsequence II
[题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/longest-uncommon-subsequence ...