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 ...
随机推荐
- Python tricks(1) -- 动态定义一个新变量
python是动态语言, 无需声明变量即可使用. 传递一个tuple, list或者dict等等方式, 有时候这种方式的使用不是很好. 对于tuple和list来说都是用下标的访问方式(即使用[]), ...
- HDU 6354 Everything Has Changed(余弦定理)多校题解
题意:源点处有个圆,然后给你m个圆(保证互不相交.内含),如果源点圆和这些原相交了,就剪掉相交的部分,问你最后周长(最外面那部分的长度). 思路:分类讨论,只有内切和相交会变化周长,然后乱搞就行了.题 ...
- POJ 1185 炮兵阵地(状压DP)题解
思路:和上一篇思路一样,但是这里要求最大能排几个,这里要开三维,记录上次和上上次的状态,再一一判定,状态转移方程为 dp[i][j][k] = max(dp[i][j][k],dp[i - 1][k] ...
- [Opencv]图像的梯度与边缘检测(转)
文章来源:https://blog.csdn.net/on2way/article/details/46851451 梯度简单来说就是求导,在图像上表现出来的就是提取图像的边缘(不管是横向的.纵向的. ...
- 简单实现Ubuntu16.04 + caffe2 + CUDA9.0 + cuDNN8.0
在Ubuntu16.04 CUDA9.0 cuDNN8.0的环境下安装caffe2 本博客比较简单,cuda9.0 cudnn8.0部分请看上一篇博客,其中详细讲了: 如何安装驱动 安装cuda 安装 ...
- ObservableCollection<T> 的同类 ListCollectionView
1:ListCollectionView : CollectionView : INotifyCollectionChanged, INotifyPropertyChanged 2:Observab ...
- 《高级Web应用程序设计》课程学习(20170911)
一.课程内容 本学期课件,点击查看 二.作业相关 上交作业的方法 访问ftp://192.168.42.254:22,登录后找到自己的姓名文件夹,放入作业即可.登录账号为stu1,密码为空 作业列表, ...
- Sql Server 开放4399端口命令行
netsh advfirewall firewall add rule name="Open Port 80" dir=in action=allow protocol=TCP l ...
- 2018HN多校
http://acm.hi-54.com/contest_problemset.php?cid=1455 A : 摩斯密码 概览问题列表状态排名 Progress Bar 时间限制:1 Sec 内存限 ...
- wikioi 1028 花店橱窗布置 最大权匹配
中文题意不描述. 链接:http://wikioi.com/problem/1028/ 这题一开始很裸的最大权二分匹配.但是原来没有接触过,KM的这个最大权不大会.然后一开始以为用最大费用最大流直接就 ...