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 ...
随机推荐
- Jquery中$与$.fn的差别
当今web开发往往离不开Jquery的使用,Jquery以其简洁的使用方式.良好的浏览器兼容性赢得了软件研发同行的青睐,作为当中的一员,自然也不例外,虽然刚開始时非常排斥Jquery,今天我谈一下对J ...
- zookeeper作为soa服务器集群的协调调度服务器
zookeeper作为soa服务器集群的协调调度服务器,当然自身也支持集群. ZooKeeper搭建系列集 ZooKeeper系列之一:ZooKeeper简介 ZooKeeper系列之二:ZooKee ...
- 【虚拟化实战】VM设计之一vCPU
作者:范军 (Frank Fan) 新浪微博:@frankfan7 虚拟机需要多少个vCPU呢?是不是个数越多性能越好呢?这方面存在着很多误区.给VM配置CPU资源的时候,要精打细算才能最大可能的利用 ...
- enum 在c中的使用
假设一个变量你须要几种可能存在的值,那么就能够被定义成为枚举类型.之所以叫枚举就是说将变量或者叫对象可能存在的情况也能够说是可能的值一一例举出来. 举个样例来说明一吧,为了让大家更明确一点,比方一个 ...
- Javascript-获取URL请求参数
function getUrlParam(){ var param = [], hash; var url = window.location.href;//获取网页的url va ...
- java_ExecutorService, CompletionService - 有返回值并行工作方式
package com.demo.test3; import java.util.ArrayList; import java.util.List; import java.util.Random; ...
- ajax生成html双引号问题
//动态创建列表 function createLists(result){ var len=result.length,i; for(i=0;i<len;i++){ $myLi = $(&qu ...
- Spring 中JCA CCI分析--转载
转载地址:http://blog.csdn.net/a154832918/article/details/6790612 J2EE提供JCA(Java Connector Architecture)规 ...
- Windows 之 获取管理员权限
新建文本文档,写入如下内容: Windows Registry Editor Version 5.00 [-HKEY_CLASSES_ROOT\*\shell\runas] [HKEY_CLASSES ...
- hdu 4632 动态规划
思路:dp[i][j]表示区间(i,j)中回文串的个数,那么dp[i][j]=dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1]:如果str[i]==str[j],那么dp[i][j ...