Gym 100803C — Shopping
来源:互联网 发布:如何使用jade软件 编辑:程序博客网 时间:2024/05/18 00:31
题目链接:Shopping
题意
在一条街上有1-n个店,你一开始在0这个位置,你需要访问每个店,并且最后到n+1这个点
然后有m个限制,就给你ci,di
表示你去ci这个店之前,你必须先到bi这个点才行
保证di>ci
问你最小距离走多少
贪心 少走回头路,那就走最大闭环 每走一次闭环 这段路就多走两次
代码参考自:http://www.cnblogs.com/qscqesze/p/5143061.html
#include<stdio.h>#include<algorithm>#define maxn 1010using namespace std;int main(){ int n,m,i,j,r[maxn],x,y,ans; while(scanf("%d%d",&n,&m)!=EOF) { for(i=1;i<=n+1;i++) { r[i]=i; } while(m--) { scanf("%d%d",&x,&y); r[x]=max(r[x],y); } ans=n+1; for(i=1;i<=n;) { int t=r[i]; int now=i; while(now<=t) { t=max(t,r[now]); now++; } ans+=2*(t-i); i=now; } printf("%d\n",ans); }}
阅读全文
0 0
- Gym 100803C — Shopping
- Codeforces Gym 100803C Shopping 贪心好题
- Shopping Gym
- Gym 101201J Shopping(RMQ +二分 )
- gym 101201 fast-en J Shopping
- C - Patrick and Shopping
- shopping
- shopping
- Shopping
- Shopping
- shopping
- Shopping
- CodeForces Gym 100114C
- CodeForces Gym 100735C
- Gym 100971C Triangles
- codeforces Gym-101246C
- Codeforces gym 101243 C
- Gym 101164.C
- ORB 特征点检测匹配算法
- 实现html5项目跳转并传数据到安卓,在activity之间进行传输
- 1
- JVM笔记——初识
- gcc/mpicc 编译器 undefined reference to ... 问题的解决
- Gym 100803C — Shopping
- DFS_棋盘问题
- zabbix监控db2命令
- hadoop在eclipse上的安装
- Eclipse 中最常用的快捷键大全
- 易错知识点整理
- 7.14matlab 数组
- error: reference to 'left' is ambiguous
- mybatis-plugin插件破解