xtu read problem training B - Tour
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
Write a program that, given a set of n points in the plane, computes the shortest closed tour that connects the points according to John's strategy.
Input
Output
Sample Input
3
1 1
2 3
3 1
4
1 1
2 3
3 1
4 2
Sample Output
6.47
7.89 解题:据说是双调dp,看不懂,费用流貌似也可以解。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn = ;
const int INF = 0x3f3f3f3f;
struct Point {
int x,y;
bool operator<(const Point &t)const {
return x < t.x;
}
} p[maxn];
double ds[maxn][maxn],dp[maxn][maxn];
double calc(int a,int b) {
LL x = p[a].x - p[b].x;
LL y = p[a].y - p[b].y;
double ret = x*x + y*y;
return sqrt(ret);
}
int main() {
int n;
while(~scanf("%d",&n)) {
for(int i = ; i <= n; ++i)
scanf("%d %d",&p[i].x,&p[i].y);
sort(p+,p+n+);
for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j)
ds[i][j] = calc(i,j);
dp[][] = ds[][];
for(int i = ; i <= n; ++i) {
dp[i][i-] = INF;
for(int j = ; j < i-; ++j) {
dp[i][j] = dp[i-][j] + ds[i-][i];
dp[i][i-] = min(dp[i][i-],dp[i-][j] + ds[j][i]);
}
}
printf("%.2f\n",dp[n][n-]+ds[n-][n]);
}
return ;
}
xtu read problem training B - Tour的更多相关文章
- xtu read problem training 3 B - Gears
Gears Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID: 3789 ...
- xtu read problem training 3 A - The Child and Homework
The Child and Homework Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on Code ...
- xtu read problem training 2 B - In 7-bit
In 7-bit Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID: 3 ...
- xtu read problem training 4 A - Moving Tables
Moving Tables Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ...
- xtu read problem training 4 B - Multiplication Puzzle
Multiplication Puzzle Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. O ...
- xtu read problem training A - Dividing
A - Dividing Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Descri ...
- TSP-UK49687
Copied From:http://www.math.uwaterloo.ca/tsp/uk/index.html Shortest possible tour to nearly every pu ...
- A Gentle Guide to Machine Learning
A Gentle Guide to Machine Learning Machine Learning is a subfield within Artificial Intelligence tha ...
- Bias vs. Variance(1)--diagnosing bias vs. variance
我们的函数是有high bias problem(underfitting problem)还是 high variance problem(overfitting problem),区分它们很得要, ...
随机推荐
- python关于文件的一些记录
1.文件打开: file("data.txt")或open("data.txt")注意不要漏了文件的后缀.(不加参数时,file为你默认为'r',reading ...
- python_面向对象进阶(7)
第1章 面向对象特性—继承(补充) 1.1 接口类.抽象类介绍 1.2 接口类 1.3 接口类应用过程 1.3.1 第一版:完成多种支付方式接口 1.3.2 第二版: 归一化设计,统一支付方式 1.3 ...
- Camera和 tris,verts的优化
Unity的Camera组件有很多可调节的参数,当需要做优化的时候,stats面板中的tris和verts这两个重点项都与Camera组件的参数有很大关系,有些参数的意义Unity手册说得不够详细,经 ...
- xutils3批量上传文件
前几天开发安卓要用到文件批量上传,就是上传图片,视频,文件之类的用到Xutil3框架,用 RequestParams params = new RequestParams(url); params.a ...
- pandas中loc-iloc-ix的使用
转自:https://www.jianshu.com/p/d6a9845a0a34 Pandas中loc,iloc,ix的使用 使用 iloc 从DataFrame中筛选数据 iloc 是基于“位置” ...
- ubuntu4.04服务器添加虚拟主机
buntu 14.04配置虚拟主机 虚拟主机常用于在一个单独的IP地址上提供多个域名的网站服务.如果有人想在单个VPS的单个IP地址运行多个网站,这是非常有用的.在这个教程中,让我告诉你如何设置在 ...
- Qt 为QPushButton、QLabel添加鼠标移入移出事件
QT 为QPushButton.QLabel添加鼠标移入移出事件**要实现的效果:**鼠标移入QPushButton时与移出时按钮变换字体颜色,鼠标移入QLabel时显示上面的文字,移出时不显示.** ...
- this.$emit('on-select-change' emit里面不能写大写字母
this.$emit('on-select-change' emit里面不能写大写字母 刚试了下 也能写大写 但是 两边就都写一样就完了,就都写成带-的就完了
- postman的关联,即如何在请求中引用上次请求返回的值
做接口测试,一定会遇到这种情况,需要拿上次请求的值在本次请求中使用,比如,我们去测试一个东西,要去登录才能做其他的操作,需要拿到登录返回数据中的某些字段,比如,token啊等... 如果发一次请求,就 ...
- sh脚本写法
1.shell注释符号: 1. 单行注释: “#” 2. 多行注释: : << ! 语句1 语句2 语句3 语句4 ! http://blog.csdn.net/lansesl2008/a ...