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"/> ...
随机推荐
- Java Queue 各种方法的区别
再Java里的某些集合类,其实是实现了多个接口的,所以就会同时又多种方法针对同一种操作,比如LinkedList类. 首先看一下java集合类的继承关系图: 这里简单对其重复的方法做点简单的区分. o ...
- 《Windows驱动开发技术详解》之Windows内存管理
虚拟内存地址 Windows所有的程序(Ring0和Ring3层)可以操作的都是虚拟内存.有一部分单元会和物理内存对应起来,但并非一一对应,多个虚拟内存页可以映射同一个物理内存页.还有一部分单元会被映 ...
- ContentPlaceHolderID属性
用来对应包含与当前内容关联的 ContentPlaceHolder 的 ID啊 说白了就是去找母版页相应的ContentPlaceHolder ,然后把内容扔进那里面去 <asp:Content ...
- JavaScript高级程序设计:第十七章
错误处理与调试 一.错误处理 1.try-catch语句: ECMA-262第3版引入了try-catch语句,作为javascript中处理异常的一种标准方式.基本的语法如下: try { //可能 ...
- Linux下开启nfs服务
1.什么是NFS(Network FileSystem) NFS 就是 Network FileSystem 的缩写,最早之前是由 Sun 所发展出来的.他最大的功能就是可以透过网络,让不同的机器.不 ...
- arTemplate解析语法
模板解析语法 defaults.parser = function (code, options) { // var match = code.match(/([\w\$]*)(\b.*)/); // ...
- hdu 1212 Big Number(大数取模)
Problem Description As we know, Big Number is always troublesome. But it's really important in our A ...
- Android onTouchEvent方法
onTouchEvent方法简介 前面已经介绍了手机键盘事件的处理方法,接下来将介绍手机屏幕事件的处理方法onTouchEvent.该方法在View类中的定义,并且所有的View子类全部重写了该方法, ...
- PHP实现队列的原理
关于的队列的介绍,我这里就不多讲了,随便百度一下都很多 用过laravel框架的童鞋都知道其自带队列功能,之前我很费解,PHP只是一个脚本,有超时机制 为什么能不停的去执行队列呢? 带着这个问题,在网 ...
- asp.net控件ControlToValidate同OnClientClick冲突解决办法
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Error ...