ural1772 Ski-Trails for Robots
Ski-Trails for Robots
Memory limit: 64 MB
Input
Output
Sample
input | output |
---|---|
5 3 2 |
6 |
分析:参考http://blog.csdn.net/xcszbdnl/article/details/38494201;
对于当前障碍物,在障碍物旁边的点必然是可到达的最短的路程的点;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=1e5+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p%mod;p=p*p%mod;q>>=;}return f;}
int n,m,k,t,s;
set<int>p,q;
set<int>::iterator now,pr,la;
ll dp[maxn];
int main()
{
int i,j;
scanf("%d%d%d",&n,&s,&k);
rep(i,,n+)dp[i]=1e18;
p.insert(),p.insert(n+),p.insert(s);
dp[s]=;
while(k--)
{
int a,b;
scanf("%d%d",&a,&b);
if(a>)
{
a--;
p.insert(a);
now=p.find(a);
pr=--now;
++now;
la=++now;
--now;
if(dp[*now]>dp[*pr]+(*now)-(*pr))dp[*now]=dp[*pr]+(*now)-(*pr);
if(dp[*now]>dp[*la]+(*la)-(*now))dp[*now]=dp[*la]+(*la)-(*now);
a++;
}
if(b<n)
{
b++;
p.insert(b);
now=p.find(b);
pr=--now;
++now;
la=++now;
--now;
if(dp[*now]>dp[*pr]+(*now)-(*pr))dp[*now]=dp[*pr]+(*now)-(*pr);
if(dp[*now]>dp[*la]+(*la)-(*now))dp[*now]=dp[*la]+(*la)-(*now);
b--;
}
q.clear();
for(now=p.lower_bound(a);now!=p.end()&&*now<=b;now++)q.insert(*now);
for(int x:q)p.erase(x),dp[x]=1e18;
}
ll mi=1e18;
rep(i,,n)if(mi>dp[i])mi=dp[i];
printf("%lld\n",mi);
//system("pause");
return ;
}
ural1772 Ski-Trails for Robots的更多相关文章
- 网站 robots.txt 文件编写
网站 robots.txt 文件编写 Intro robots.txt 是网站根目录下的一个纯文本文件,在这个文件中网站管理者可以声明该网站中不想被robots访问的部分,或者指定搜索引擎只收录指定的 ...
- Robots.txt - 禁止爬虫(转)
Robots.txt - 禁止爬虫 robots.txt用于禁止网络爬虫访问网站指定目录.robots.txt的格式采用面向行的语法:空行.注释行(以#打头).规则行.规则行的格式为:Field: v ...
- (转载)robots.txt写法大全和robots.txt语法的作用
1如果允许所有搜索引擎访问网站的所有部分的话 我们可以建立一个空白的文本文档,命名为robots.txt放在网站的根目录下即可.robots.txt写法如下:User-agent: *Disallow ...
- 2016 ccpc 网络选拔赛 F. Robots
Robots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- Codeforces 209 C. Trails and Glades
Vasya went for a walk in the park. The park has n glades, numbered from 1 to n. There are m trails b ...
- robots.txt文件没错,为何总提示封禁
大家好,我的robots.txt文件没错,为何百度总提示封禁,哪位高人帮我看看原因,在此谢过. 我的站点www.haokda.com,robots.txt如下: ## robots.txt for P ...
- robots笔记以免忘记
html头部标签写法: <meta name="robots" content="index,follow" /> content中的值决定允许抓取 ...
- [题解]USACO 1.3 Ski Course Design
Ski Course Design Farmer John has N hills on his farm (1 <= N <= 1,000), each with an integer ...
- springMVC robots.txt 处理
正常情况这样就好使 <mvc:resources mapping="/robots.txt" location="/lib/robots.txt"/> ...
随机推荐
- 转:应用JMeter测试solr请求
使用JMeter测试solr请求 一.安装JMeter 在官网http://jmeter.apache.org/download_jmeter.cgi下载JMeter 直接解压JMeter安装包 Li ...
- Get和Post请求的区别
Get:组拼url的方式,提交数据到服务器,url最大长度不能超过4K; Post:直接浏览器把数据写给服务器,流的形式.
- 高级CSS
target="_black"新窗口打开,且打开第二个链接出来的页面覆盖第一个页面 .ui-pg-table td[dir="ltr"]{*width:94px ...
- List-----Array
1.Definition Arry数组是一种连续储存的List 储存方式:将线性表中的元素一次储存在连续的储存空间中. Computer's logical structure: 逻辑位置上相邻的元素 ...
- Self Numbers
Self Numbers Time Limit : 20000/10000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tota ...
- 解决centos网速特别慢的最佳解决办法
摘自:http://www.centoscn.com/CentosBug/osbug/2014/0614/3138.html 我使用了centOS,但是发现网速实在是卡得几乎不能上网,连百度都打不开, ...
- 设计一种前端数据延迟加载的jQuery插件(2)
背景 最近看到很多网站都运用到了一种前端数据延迟加载技术,包括淘宝,新浪网等等,这样做的目的可以使得一些未显示的图片随 着滚动条的滚动进行延迟显示. 好处显而易见,可以减少前端对于图片的Http请求, ...
- Androidndk开发打包时我们应该如何注意平台的兼容(x86,arm,arm-v7a)
很多朋友在开发Android JNI的的时候,会遇到findlibrary returned null的错误,因为某种原因,so没有打包到apk中.下面浅析下引起该错误的原因以及平台兼容性问题. 一. ...
- 笨方法学python--变量和命名
1 =(单等号)和==(双等号)的区别 =用来赋值, ==用来判断是否相等 2 x = 100 在操作符2侧加空格,易读 3 打印时,进行字符串拼接 print "there are&quo ...
- 关于web.xml的格式
先是filter 再是<filter-mapping> 然后<servlet> 再是<servlet-mapping> 这是一种规范基于j2ee 在开发的过程中一 ...