UVaLive6834 Shopping
题意:一条直线上有n个点,标号从1到n,起点为0,终点为N+1,给定m个限制关系(ci,di),访问ci点前必须先访问di点,每两个点之间是单位距离,求在限制条件下,从起点到终点访问完所有的点的最短距离。
分析:画图模拟一下可知,从起点到终点的N+1这段距离是必须的,若想距离最短,必须去重。
比如以下样例,
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {, , -, };
const int dc[] = {-, , , };
const double pi = acos(-1.0);
const double eps = 1e-;
const int MAXN = + ;
const int MAXT = + ;
using namespace std;
struct P
{
int x, y;
bool operator < (const P& a)const
{
return x < a.x || (x == a.x && y < a.y);
}
};
int main()
{
int N, m;
while(scanf("%d%d", &N, &m) == )
{
if(m == )
{
printf("%d\n", N + );
continue;
}
int ans = N + ;
P num[];
for(int i = ; i < m; ++i)
scanf("%d%d", &num[i].x, &num[i].y);
sort(num, num + m);
int s = num[].x;
int e = num[].y;
for(int i = ; i < m; ++i)
{
if(num[i].x > num[i].y) continue;
if(num[i].x >= s && num[i].y <= e) continue;
else if(num[i].x >= s && num[i].x <= e && num[i].y >= e)
e = num[i].y;
else
{
ans += * (e - s);
s = num[i].x;
e = num[i].y;
}
}
ans += * (e - s);
printf("%d\n", ans);
}
return ;
}
UVaLive6834 Shopping的更多相关文章
- Shopping(山东省第一届ACM省赛)
Shopping Time Limit: 1000MS Memory limit: 65536K 题目描述 Saya and Kudo go shopping together.You can ass ...
- sdutoj 2154 Shopping
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2154 Shopping Time Limit: ...
- Shopping(SPFA+DFS HDU3768)
Shopping Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- eclipse中 起动tomcat时报Multiple Contexts have a path of "/shopping"
eclipse中 启动tomcat时报Multiple Contexts have a path of "/shopping". 这个是由于你的server服务器中的server. ...
- 洛谷P2732 商店购物 Shopping Offers
P2732 商店购物 Shopping Offers 23通过 41提交 题目提供者该用户不存在 标签USACO 难度提高+/省选- 提交 讨论 题解 最新讨论 暂时没有讨论 题目背景 在商店中, ...
- UVALive - 6572 Shopping Malls floyd
题目链接: http://acm.hust.edu.cn/vjudge/problem/48416 Shopping Malls Time Limit: 3000MS 问题描述 We want to ...
- Codeforces Gym 100803C Shopping 贪心
Shopping 题目连接: http://codeforces.com/gym/100803/attachments Description Your friend will enjoy shopp ...
- Codeforces Round #332 (Div. 2) A. Patrick and Shopping 水题
A. Patrick and Shopping Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- poj 1170 Shopping Offers
Shopping Offers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4696 Accepted: 1967 D ...
随机推荐
- [置顶] How to dump redo log entry?
1.转储针对特定数据块(4号文件的第10-20号数据块)修改的 redo entry select file#,name,blocks from v$datafile; FILE# NAME ...
- ListView删除选中的多项目
//ListView删除选中的多项目function DeleteMultSelItems(ListView:TListView):Boolean;var I: Integer;begin Res ...
- javascript常见编程模式举例
近期买到手了一本<javascript框架设计>,具体介绍开发js框架所用到的知识.初读一点,乐帝脆弱的理论修养就暴露无遗了,所以专门加强理论修养,重看javascript编程模式的举例. ...
- 测试JS
<html> <head> </head> <body> <script> function loadScript(url, callbac ...
- ExpandableListView 箭头靠右
ExpandableListView 默认标示箭头是在左边的,当左边有图片时,不是太好看,想把它放在右边,这么简单的事可我折腾死了,还好给我找到了. 参照了以下链接: expandableListvi ...
- SVN是什么,svn的目录结构
Svn是一个离线的代码管理,可以多个人一起修改,然后再将修改的内容提交到Svn中.每一个svn服务器中的数据存储单位叫做存储,但是你不仅仅可以把整个存储当作你维护的内容,也可以将其中的某个分支目录像根 ...
- 为laravel分页样式制定class
做的项目有一个上翻页和下翻页,使用了框架提供的
- 解决Kscope中文乱码问题
当安装Kscope完成后,然后配置以下三个路径:Cscope path:/usr/bin/cscopeCtags path:/usr/bin/ctagsDot path:/usr/bin/dot 对于 ...
- eclipse按Crl+鼠标左键,找不到源文件的解决办法。
这种情况一般发生在tomcat的之中,原因是缺少类的源文件.在jdk中很少见,jdk中自带类的源文件,配置jdk的时候就已经将其加载进来了.而tomcat之中没有带类的源文件,需要自己去网上单独下载. ...
- js中replace的用法【转】
1.replace方法的语法是:stringObj.replace(rgExp, replaceText) 其中stringObj是字符串(string),reExp可以是正则表达式对象(RegExp ...