test20181024 ming
题意

分析
考场做法
考虑二分答案,R开到1e9就能过了。
判断答案合法,就判断时间和是否超过拥有的时间就行了。但要把di从小到大排序,不然容易验证贪心是错的。
时间复杂度\(O(n \log n)\)
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<complex>
#include<cassert>
#define rg register
#define il inline
#define co const
#pragma GCC optimize ("O0")
using namespace std;
template<class T> il T read()
{
T data=0;
int w=1;
char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-')
w=-1;
ch=getchar();
}
while(isdigit(ch))
data=10*data+ch-'0',ch=getchar();
return data*w;
}
template<class T> il T read(T&x)
{
return x=read<T>();
}
typedef long long ll;
const int INF=0x7fffffff;
const int MAXN=1e5+7;
int n;
struct $
{
int t,d;
bool operator<(const $&rhs)const
{
return d<rhs.d;
}
}a[MAXN];
bool judge(int M)
{
ll sum=M;
for(int i=1;i<=n;++i)
{
sum+=a[i].d-a[i-1].d;
sum-=a[i].t;
if(sum<0)
return 0;
}
return 1;
}
int main()
{
freopen("ming.in","r",stdin);
freopen("ming.out","w",stdout);
read(n);
for(int i=1;i<=n;++i)
{
read(a[i].t);read(a[i].d);
}
sort(a+1,a+n+1);
int L=0,R=1e9,ans;
while(L<=R)
{
int M=(L+R)>>1;
if(judge(M))
ans=M,R=M-1;
else
L=M+1;
}
printf("%d\n",ans);
// fclose(stdin);
// fclose(stdout);
return 0;
}
标解

旁边的大佬L君:类似B君讲过的一道题,发现可分析贡献排序,时间复杂度\(O(n \log n)\)
#include<bits/stdc++.h>
using namespace std;
#define gc c=getchar()
#define r(x) read(x)
#define ll long long
template<typename T>
inline void read(T&x){
x=0;T k=1;char gc;
while(!isdigit(c)){if(c=='-')k=-1;gc;}
while(isdigit(c)){x=x*10+c-'0';gc;}x*=k;
}
const int N=1e5+7;
struct Data{
ll t,d;
}A[N];
inline bool operator < (const Data &a,const Data &b){
return a.d<b.d;
}
int main(){
freopen("ming.in","r",stdin);
freopen("ming.out","w",stdout);
int n;r(n);
for(int i=0;i<n;++i)r(A[i].t),r(A[i].d);
sort(A,A+n);
ll ans=0,tim=0;
for(int i=0;i<n;++i){
tim+=A[i].t;
ans=max(ans,tim-A[i].d);
}
printf("%lld\n",ans);
}
test20181024 ming的更多相关文章
- HDU 4349 Xiao Ming's Hope lucas定理
Xiao Ming's Hope Time Limit:1000MS Memory Limit:32768KB Description Xiao Ming likes counting nu ...
- Hdu4349 Xiao Ming's Hope
Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Ming Rpc
原文地址:http://iwantmoon.com/Post/487ab43d609f49d28ff4228241e2b7c7 Rpc(Remote Procedure Call Protocal)远 ...
- ubuntu下安装Ming的教程
Ming是一个操纵swf(flash movice)的C库,支持php. ruby. python等语言. 重要提示: 在安装Ming之前,应该准备好你的系统,特别是Linux/Unix系统,如果你对 ...
- BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)
Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- HDU 5433 Xiao Ming climbing dp
Xiao Ming climbing Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/ ...
- hdu 5612 Baby Ming and Matrix games
Baby Ming and Matrix games 题意: 给一个矩形,两个0~9的数字之间隔一个数学运算符(‘+’,’-‘,’*’,’/’),其中’/’表示分数除,再给一个目标的值,问是否存在从一 ...
- hdu 5612 Baby Ming and Matrix games(dfs暴力)
Problem Description These few days, Baby Ming is addicted to playing a matrix game. Given a n∗m matr ...
- hdu 5611 Baby Ming and phone number(模拟)
Problem Description Baby Ming collected lots of cell phone numbers, and he wants to sell them for mo ...
随机推荐
- 吴恩达深度学习笔记(deeplearning.ai)之循环神经网络(RNN)(三)
1. 导读 本节内容介绍普通RNN的弊端,从而引入各种变体RNN,主要讲述GRU与LSTM的工作原理. 事先声明,本人采用ng在课堂上所使用的符号系统,与某些学术文献上的命名有所不同,不过核心思想都是 ...
- Python3:Requests模块的异常值处理
Python3:Requests模块的异常值处理 用Python的requests模块进行爬虫时,一个简单高效的模块就是requests模块,利用get()或者post()函数,发送请求. 但是在真正 ...
- [CDOJ887]轻音乐同好会(跳石头)
此题已经无法在UESTC上上传,网上只有玄学题解 题目 题目描述 雪菜为了能让冬马参加轻音乐同好会,瞒着春希,和冬马见面. 为了增进感情,雪菜拉着还没缓过神来的冬马进了游戏厅-- 游戏要求两名玩家在排 ...
- 2012NOIP模拟试题
做的时候觉得这套题好简单,结果一看发现是2012年的模拟题,估计就是普及+的难度吧,AK无压力 总结 第一题状压我智障的调了好几分钟,因为我的最终状态写的1<<n,智障了 第三题的dfs调 ...
- LA 4636 积木艺术
https://vjudge.net/problem/UVALive-4636 题意: 给出正视图和侧视图,判断最少要用多少个立方体. 思路: 首先正视图里出现的积木个数都是必须的,记录下每一列积木的 ...
- css 基础 - 3
css 基础 - 3 20161128 一. 元素的距离计算 1,两个水平方向的容器s1,s2之间的距离计算为s: s = s1的margin-right + s2的margin-left(+默认 ...
- (CLR via C#学习笔记)异步操作 - 线程池
一 线程池基础 1.线程池维护了一个操作请求队列,将请求的操作追加到线程池队列中,线程池的代码从队列中提取操作项,派发给线程池中的线程; 2.CLR初始化时,线程池中是没有线程的,当有操作派发给线程池 ...
- ros service
Server部分: #!/usr/bin/env python import sys import os import rospy #from beginner.srv import * from b ...
- nginx第三方模块安装方法
nginx第三方模块安装方法 ./configure --prefix=/你的安装目录 --add-module=/第三方模块目录 比如echo模块. 没安装前,使用测试. location /tes ...
- Proxy(代理)
意图: 为其他对象提供一种代理以控制对这个对象的访问. 适用性: 在需要用比较通用和复杂的对象指针代替简单的指针的时候,使用Proxy模式.下面是一 些可以使用Proxy 模式常见情况: 1) 远程代 ...