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 ...
随机推荐
- 搞笑世界杯(codevs 1060)
题目描述 Description 随着世界杯小组赛的结束,法国,阿根廷等世界强队都纷纷被淘汰,让人心痛不已. 于是有 人组织了一场搞笑世界杯,将这些被淘汰的强队重新组织起来和世界杯一同比赛.你和你的朋 ...
- 自己动手编译hadoop-2.5.2源码
搭建环境:Centos x 6.5 64bit (后来:我才知道原来官网上发布的就是64位的,不过这个对我来说是个学习过程,对以后进行其他平台编译的时候有帮助!) 1.安装JDK 我这里用的是64位 ...
- SQLSERVER查询连接数
SELECT * FROM [Master].[dbo].[SYSPROCESSES] WHERE [DBID] IN (SELECT [DBID]FROM [Master].[dbo].[SYSDA ...
- TCP 四次握手
TCP协议中的三次握手和四次挥手(图解) http://blog.csdn.net/whuslei/article/details/6667471/
- HTML5学习之视频与音频(三)
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- Linux 下 Console / 控制台 复制粘贴快捷键
Linux下复制粘贴快捷键 1. 在终端下: 复制命令:Ctrl + Shift + C 组合键. 粘贴命令:Ctrl + Shift + V 组合键. 2. 在控制台下: 复制命令:Ctrl + ...
- Delphi面向对象编程
一.面向对象介绍 OOP是使用独立的对象(包含数据和代码)作为应用程序模块的范例.虽然OOP不能使得代码容易编写,但是它能够使得代码易于维护.将数据和代码结合在一起,能够使定位和修复错误的工作简单化, ...
- MVC中Action 过滤
总结Action过滤器实用功能,常用的分为以下两个方面: 1.Action过滤器主要功能就是针对客服端请求过来的对象行为进行过滤,类似于门卫或者保安的职能,通过Action过滤能够避免一些非必要的深层 ...
- 攻城狮在路上(壹) Hibernate(九)--- Hibernate的映射类型
Hibernate采用映射类型作为Java类型和SQL类型的桥梁,对应type属性.分为两种:内置映射类型和客户化映射类型.一.内置映射类型: 1.Java基本类型的Hibernate映射类型: Ja ...
- android 入门-android属性介绍
android:visibility="gone" 不保留view控件所占有的空间 隐藏 android:visibility="invisible" 保留 ...