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),区分它们很得要, ...
随机推荐
- Lucas+中国剩余定理 HDOJ 5446 Unknown Treasure
题目传送门 题意:很裸,就是求C (n, m) % (p1 * p2 * p3 * .... * pk) 分析:首先n,m<= 1e18, 要用到Lucas定理求大组合数取模,当然p[]的乘积& ...
- h5-18-文件操作-兼容判断
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Git命令---递归克隆
git clone --recursive https://github.com/rbgirshick/fast-rcnn.git Git命令 --recursive 会递归克隆fast-rcnn项目 ...
- C51之数据范围
在C51中各数据类型的范围如下:如果宏常量大于65536,则要加UL后缀:乘法运算不能只将结果强制类型转换,而应在被乘数前加(unsigned long)强制转换. 2 因为RAM有限,所以运算量大的 ...
- 百度地图API简单初始化
<script src="http://api.map.baidu.com/api?key=&v=2.0&ak=youkey"></script& ...
- apt-get的一些坑
apt-get update:更新安装列表apt-get upgrade:升级软件apt-get install software_name :安装软件apt-get --purge remove ...
- [BZOJ1050][HAOI2006]旅行comf 枚举+并查集
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1050 将边排序,枚举边权最小的边,依次加边直到S和T连通,更新答案. #include&l ...
- CCF|最大波动|Java|100
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Sc ...
- element ui select组件和table做分页完整功能和二级联动效果
<template> <div class="index_box"> <div class="search_box"> &l ...
- oracle补丁类型
名称 说明 Release ¤ 标准产品发布.如Oracle Database 10g Release 2的第一个发行版本为10.2.0.1,可以在OTN.edelivery等站点上公开下载 Patc ...