Problem C Shopping 闭环贪心
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
int fa[maxn]; int main(){
int n, m;
scanf("%d%d", &n, &m);
for(int i = ; i <= n+; i++) fa[i] = i;
for(int i = ; i <= m; i++){
int x, y;
scanf("%d%d", &x, &y);
fa[x] = max(fa[x], y);
}
long long ans = n+;
int l = , r = ;
for(int i = ; i <= n; ){
r = fa[i];
int now = i;
while(now <= r){
r = max(r, fa[now]);
now++;
}
ans += *(r-i);
i = now;
}
printf("%lld\n", ans);
return ;
}
在一条街上有1-n个店,你一开始在0这个位置,你需要访问每个店,并且最后到n+1这个点
然后有m个限制,就给你ci,di
表示你去ci这个店之前,你必须先到di这个点才行
保证di>ci
问你最小距离走多少
往回走一次,再走过去就好了!!!!
Problem C Shopping 闭环贪心的更多相关文章
- Problem UVA11134-Fabled Rooks(贪心)
Problem UVA11134-Fabled Rooks Accept: 716 Submit: 6134Time Limit: 3000mSec Problem Description We w ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划
There are n people and k keys on a straight line. Every person wants to get to the office which is l ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 828D) - 贪心
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...
- Codeforces Round #371 (Div. 1) C. Sonya and Problem Wihtout a Legend 贪心
C. Sonya and Problem Wihtout a Legend 题目连接: http://codeforces.com/contest/713/problem/C Description ...
- UVA 10026 Shoemaker's Problem 鞋匠的难题 贪心+排序
题意:鞋匠一口气接到了不少生意,但是做鞋需要时间,鞋匠只能一双一双地做,根据协议每笔生意如果拖延了要罚钱. 给出每笔生意需要的天数和每天的罚钱数,求出最小罚钱的排列顺序. 只要按罚款/天数去从大到小排 ...
- AT3949-[AGC022D]Shopping【贪心】
正题 题目链接:https://www.luogu.com.cn/problem/AT3949 题目大意 长度为\(L\)的坐标轴上,给出\(n\)个点,每个点\(x_i\)需要购物\(t_i\)的时 ...
- FZU Problem 2221 RunningMan(贪心)
一开始就跑偏了,耽误了很长时间,我和队友都想到博弈上去了...我严重怀疑自己被前几个博弈题给洗脑了...贪心的做法其实就是我们分两种情况,因为A先出,所以B在第一组可以选择是赢或输,如果要输,那直接不 ...
- 华农oj Problem J: 幻化【贪心/抽屉原理】
Problem J: 幻化 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 18 Solved: 3 [Submit][Status][Web Board ...
- 雅礼培训 Problem B 【图论 + 贪心】
题意 A和B在树上轮流选点,记A的联通块个数为\(x\),B的联通块个数为\(y\) A使\(x - y\)最大,B使\(x - y\) 二人采取最优策略,求\(x-y\) 题解 树联通块个数 = 点 ...
随机推荐
- 【AMAD】django-formapi -- 一个DJANGO API框架,可使用签名request,可使用form作为API的验证工具
动机 简介 个人评分 动机 如何快速构建API,使用view就行了? 如果快速构建一个可以验证参数的API,使用django-formapi1吧! 简介 class DivisionCall(call ...
- Cpython全局解释器锁原理剖析
"""In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple ...
- c++ erase 中的坑
先看一段正常的代码 #include <iostream> #include <string> using namespace std; int main() { " ...
- Petya and Construction Set(图的构造) Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises)
题意:https://codeforc.es/contest/1214/problem/E 有2n个点,每个2*i和2*i-1的距离必须是Di(<=n),现在让你构造这个树. 思路: 因为Di小 ...
- localStorage 杂记
localStorage html5标准 Web 存储现在的主流浏览器,包括IE 8+.Chrome 4+.Firefox 3.5+.Opera 10.5+.Safari 4+.iPhone 2+.A ...
- PBOC第八部分和第十一部分关于TYPEA总结(二)——传输协议(ISO14443-4)
二.传输协议(ISO14443-4)(8,P50 11,P30) 1.选择应答请求(RATS) 使用RATS命令和PICC协商通讯的最大帧长度(FSD和FSC).帧等待时间(FWT)和启动帧保护时间( ...
- CF 666C & 牛客 36D
给定字符串S, 求有多少长为$n$的字符串T, 使得S为T的子序列. 可以得到转移矩阵为 $\begin{equation}A=\begin{bmatrix}25 & 0 & 0 &a ...
- SQLServer 导入大容量sql文件
cmd命令行,管理员身份运行 执行以下语句:E:\dbbak\abhs\SmartEnglish_data.sql 为文件路径,AbhsEnglish 为要导入的数据库 sqlcmd -i E:\db ...
- L1-025. 正整数A+B 简单复习一下,。
本题的目标很简单,就是求两个正整数A和B的和,其中A和B都在区间[1,1000].稍微有点麻烦的是,输入并不保证是两个正整数. 输入格式: 输入在一行给出A和B,其间以空格分开.问题是A和B不一定是满 ...
- thymeleaf 模板使用 之 前台界面获取后台属性值
使用Thymeleaf模板时,如果需要在js中获取后台传值,那么需要用内联JS写法获取 [姿势很重要] 一.后台通过Model的addAttribute方法向前台传值 1.js获取后台属性值(--内联 ...