[bzoj1359][Baltic2009]Candy
给定N个数对$(T_i,S_i)$,表示时刻$S_i$时在位置$T_i$处出现一粒糖果。有一些机器人可供使用,每个机器人可花费一单位时间向相邻位置移动。要求用最少的机器人接到全部糖果。时刻0时机器人位置可自行安排。
#include<bits/stdc++.h>
using namespace std;
const int N=;
typedef pair<int,int> P;
inline int read(){
int r=,c=getchar();
while(!isdigit(c))c=getchar();
while(isdigit(c))
r=r*+c-'',c=getchar();
return r;
}
int ans,n;P a[N];
set<int>S;
set<int>::iterator it;
int main(){
ans=n=read();
for(int i=;i<=n;i++){
int y=read(),x=read();
a[i]=P(x+y,x-y);
}
sort(a+,a+n+);
for(int i=;i<=n;i++){
int t=a[i].second;
it=S.upper_bound(t);
if(it!=S.begin())
S.erase(--it),ans--;
S.insert(t);
}
printf("%d\n",ans);
}
[bzoj1359][Baltic2009]Candy的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- [LeetCode] Candy 分糖果问题
There are N children standing in a line. Each child is assigned a rating value. You are giving candi ...
- Leetcode Candy
There are N children standing in a line. Each child is assigned a rating value. You are giving candi ...
- LeetCode 135 Candy(贪心算法)
135. Candy There are N children standing in a line. Each child is assigned a rating value. You are g ...
- [LeetCode][Java]Candy@LeetCode
Candy There are N children standing in a line. Each child is assigned a rating value. You are giving ...
- 【leetcode】Candy(hard) 自己做出来了 但别人的更好
There are N children standing in a line. Each child is assigned a rating value. You are giving candi ...
- 【leetcode】Candy
题目描述: There are N children standing in a line. Each child is assigned a rating value. You are giving ...
- Codeforces Round #229 (Div. 2) C. Inna and Candy Boxes 树状数组s
C. Inna and Candy Boxes Inna loves sweets very much. She has n closed present boxes lines up in a ...
- [LintCode] Candy 分糖果问题
There are N children standing in a line. Each child is assigned a rating value. You are giving candi ...
随机推荐
- MyEclipse2015Stable3.0破解方法
原理大概是这样的(个人粗略分析):获取当前的日期,来设置证书失效日期,解析后生成码-->再转码,最后生成序列号. 1.新建一个Java工程,(不会安装jdk创建环境变量的,请前往传送门:链接.) ...
- codefind.pl
#!/usr/bin/perl # # Find a pattern in a the book's source collection (DOS/Windows version) # # (C) C ...
- python入门1 python手动编译py_compile,compileall
python运行之后会自动生产pyc文件,也可以手动编译生成pyc文件.代码如下: #coding:utf-8 """ 2018-11-03 dinghanhua 手动编 ...
- What is Thread
A thread is a fundamental unit of CPU utilization –a thread ID –a program counter –a register set –a ...
- POJ 2704 Pascal's Travels 【DFS记忆化搜索】
题目传送门:http://poj.org/problem?id=2704 Pascal's Travels Time Limit: 1000MS Memory Limit: 65536K Tota ...
- 2018.10.2 Eclipse中如何测地修改一个we项目步骤
找到项目的web.xml文件 大概的路径如下: 修改xml文件中的display-name 节点的值 下一步就是切换工作目录 显示的效果 打开最后一个文件修改 接下来找到这个文件 是部署的时候用的 运 ...
- VisualSVN Server更改SVN版本库存放路径的方法
来源:http://blog.csdn.net/tcjy1000/article/details/42023849 最近也玩起了SVN软件版本管理,在本机上安装了VisualSVN Server+To ...
- Python条件判断
计算机之所以能做很多自动化的任务,因为它可以自己做条件判断. 比如,输入用户年龄,根据年龄打印不同的内容,在Python程序中,用if语句实现: age = 20 if age >= 18: p ...
- insertAdjacentHTML与innerHTML
insertAdjacentHTML:insertAdjacentHTML() 将指定的文本解析为HTML或XML,并将结果节点插入到DOM树中的指定位置.它不会重新解析它正在使用的元素,因此它不会破 ...
- PL/SQL dev 工具连接远程服务器oracle注意点
由于Oracle的庞大,有时候我们需要在只安装Oracle客户端如plsql.toad等的情况下去连接远程数据库,可是没有安装Oracle就没有一切的配置文件去支持. 最后终于发现一个很有效的方法,O ...