ural 1143. Electric Path
1143. Electric Path
Memory limit: 64 MB
Background
Problem
Input
Output
Sample
input | output |
---|---|
4 |
50.211 |
/**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = ;
struct Point
{
DB x, y; inline void Read()
{
scanf("%lf%lf", &x, &y);
}
} arr[N];
int n;
DB dp[N][N][];
bool visit[N][N][]; inline void Input()
{
scanf("%d", &n);
for(int i = ; i <= n; i++) arr[i].Read();
} inline DB Sqr(DB x)
{
return x * x;
} inline DB Dist(const Point &A, const Point &B)
{
return sqrt(Sqr(A.x - B.x) + Sqr(A.y - B.y));
} inline DB Work(int left, int right, bool type)
{
if(left >= right) return ;
if(visit[left][right][type])
return dp[left][right][type];
visit[left][right][type] = ;
DB ret = 1.0 * INF, cnt;
if(type == )
{
cnt = Dist(arr[left], arr[left + ]);
cnt += Work(left + , right, );
ret = min(ret, cnt); cnt = Dist(arr[left], arr[right]);
cnt += Work(left + , right, );
ret = min(ret, cnt);
}
else
{
cnt = Dist(arr[right], arr[right - ]);
cnt += Work(left, right - , );
ret = min(ret, cnt); cnt = Dist(arr[right], arr[left]);
cnt += Work(left, right - , );
ret = min(ret, cnt);
} return dp[left][right][type] = ret;
} inline void Solve()
{
for(int i = n + ; i <= * n; i++)
arr[i] = arr[i - n]; DB ans = 1.0 * INF, cnt;
for(int i = ; i <= n; i++)
{
cnt = Work(i, i + n - , );
ans = min(ans, cnt);
cnt = Work(i, i + n - , );
ans = min(ans, cnt);
} printf("%.3lf\n", ans);
} int main()
{
freopen("a.in", "r", stdin);
Input();
Solve();
return ;
}
ural 1143. Electric Path的更多相关文章
- ural 1143. Electric Path(凸包上最短哈密顿路径)
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1143 题意:逆时针给一个凸包的n(n<=200)个顶点坐标,求一个最短哈密顿路径的 ...
- dp题目列表
此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...
- poj 动态规划题目列表及总结
此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...
- poj动态规划列表
[1]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 13 ...
- POJ 动态规划题目列表
]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322 ...
- poj 动态规划的主题列表和总结
此文转载别人,希望自己可以做完这些题目. 1.POJ动态规划题目列表 easy:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, ...
- 别人整理的dp题目
动态规划 动态规划 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322, 14 ...
- 别人整理的DP大全(转)
动态规划 动态规划 容易: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ...
- URAL 1525 Path
#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> us ...
随机推荐
- Mysql游标
14.6.6.1 Cursor CLOSE Syntax 14.6.6.2 Cursor DECLARE Syntax 14.6.6.3 Cursor FETCH Syntax 14.6.6.4 Cu ...
- OkHttp学习总结
This paper mainly includes the following contents okhttp ordinary operation. okhttp interceptors. Re ...
- java向oracle数据库中插入当前时间
public class Test{public static void main (String args []){ java.util.Date a = new java.util.Date(); ...
- 二、JavaScript语言--JS基础--JavaScript进阶篇--JavaScript内置对象
1.什么事对象 JavaScript 中的所有事物都是对象,如:字符串.数值.数组.函数等,每个对象带有属性和方法. 对象的属性:反映该对象某些特定的性质的,如:字符串的长度.图像的长宽等: 对象的方 ...
- DNS原理
DNS 是互联网核心协议之一.不管是上网浏览,还是编程开发,都需要了解一点它的知识. 本文详细介绍DNS的原理,以及如何运用工具软件观察它的运作.我的目标是,读完此文后,你就能完全理解DNS. 一.D ...
- Bitmap在Java中的实现和应用
>>40亿数据排序问题 给定一个最多包含40亿个随机排列的32位整数的顺序文件,找出一个不在文件中的32位整数(在文件中至少缺失这样一个数——为什么?).在具有足够内存的情况下,如何解决该 ...
- [LeetCode] Word Pattern
Word Pattern Total Accepted: 4627 Total Submissions: 17361 Difficulty: Easy Given a pattern and a st ...
- mac下php开发环境搭建+CI框架使用
一.启动apache: apachectl start 停止: apachectl stop 配置文件: vi /etc/apache2/httpd.conf 一.修改端口 因为80端口不想被占用,8 ...
- Oracle【IT实验室】数据库备份与恢复之二:SQL*Loader
2.1 基本知识 Oracle 的 SQL* LOADER 可以将外部格式化的文本数据加载到数据库表中.通常 与 SPOOL导出文本数据方法配合使用. 1.命令格式 SQLLDR keyw ...
- PHP日期操作类代码-农历-阳历转换、闰年、计算天数等
<?php class Lunar { var $MIN_YEAR = 1891; var $MAX_YEAR = 2100; var $lunarInfo = array( array(0,2 ...