[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 ...
随机推荐
- Kubernetes API server工作原理
作为Kubernetes的使用者,每天用得最多的命令就是kubectl XXX了. kubectl其实就是一个控制台,主要提供的功能: 1. 提供Kubernetes集群管理的REST API接口,包 ...
- python图片黑白化
#!/usr/bin/env python #-*- coding:utf-8 -*- from PIL import Image im = Image.open(r"C:\Users\wa ...
- javascript字面量
在JavaScript里面,字面量包括:字符串字面量(string literal ).数组字面量(array literal)和对象字面量(object literal),另外还有函数字面量(fun ...
- nutz 结合QueryResult,Record 自定义分页查询,不构建pojo 整合
public QueryResult getHistoryIncome(int d, int curPage) throws Exception { /**sql**/ Sql sql = Sqls. ...
- 动态规划(DP),Human Gene Functions
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1027 http://poj.org/problem?id=108 ...
- SpringMVC学习记录三——8 springmvc和mybatis整合
8 springmvc和mybatis整合 8.1 需求 使用springmvc和mybatis完成商品列表查询. 8.2 整合思路 springmvc+mybaits的 ...
- WebSocket消息推送(实现进行聊天)和WebSocket简介
WebSocket简介 WebSocket是HTML5开始提供的一种浏览器与服务器间进行全双工通讯的网络技术.依靠这种技术可以实现客户端和服务器端的长连接,双向实时通信.特点:事件驱动异步使用ws或者 ...
- 【luogu P3371 单源最短路径】 模板 SPFA
题目链接:https://www.luogu.org/problemnew/show/P3371 我永远都喜欢Flyod.dijkstra + heap.SPFA #include <cstdi ...
- 基于Cent os 云服务器中SVN 服务器的搭建---具体实践是可行的 一次备注便于后续查找
https://blog.csdn.net/shadowyingjian/article/details/80588544http://www.hongyanliren.com/2015m04/329 ...
- 你不知道的javaScript笔记(5)
原生函数 常用的原生函数 String() Number() Boolean() Array() Object() Function() RegExp() Date() Error() Symbol( ...