题意

分析

考场做法

考虑二分答案,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的更多相关文章

  1. HDU 4349 Xiao Ming's Hope lucas定理

    Xiao Ming's Hope Time Limit:1000MS     Memory Limit:32768KB  Description Xiao Ming likes counting nu ...

  2. Hdu4349 Xiao Ming's Hope

    Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. Ming Rpc

    原文地址:http://iwantmoon.com/Post/487ab43d609f49d28ff4228241e2b7c7 Rpc(Remote Procedure Call Protocal)远 ...

  4. ubuntu下安装Ming的教程

    Ming是一个操纵swf(flash movice)的C库,支持php. ruby. python等语言. 重要提示: 在安装Ming之前,应该准备好你的系统,特别是Linux/Unix系统,如果你对 ...

  5. 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 ( ...

  6. HDU 5433 Xiao Ming climbing dp

    Xiao Ming climbing Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/ ...

  7. hdu 5612 Baby Ming and Matrix games

    Baby Ming and Matrix games 题意: 给一个矩形,两个0~9的数字之间隔一个数学运算符(‘+’,’-‘,’*’,’/’),其中’/’表示分数除,再给一个目标的值,问是否存在从一 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. spark环境安装

    源码包下载: http://archive.apache.org/dist/spark/spark-2.1.1/v 集群环境: master 192.168.1.99 slave1 192.168.1 ...

  2. Fms3中client端与server端交互方式汇总

    系列文章导航 Flex,Fms3相关文章索引 Flex和Fms3打造在线聊天室(利用NetConnection对象和SharedObject对象) Fms3和Flex打造在线视频录制和回放 Fms3和 ...

  3. NET Framework 4.0无法安装!

    win7旗舰版无法安装CAD2012,安装NET Framework 4.0的时候就出现错误,安装NET Framework 4.0单独版也无法安装出现错误. 解决方法: 1.点击电脑桌面右下角的“开 ...

  4. 微信小程序中公用内容

    微信小程序中各个页面调用公用的js 在util.js文件中 // 跳转哪里 function go(where) { wx.reLaunch({ url: where, }) } // 将方法暴露出去 ...

  5. AngularJs 控制台

    在控制台查看$scope对象 html: 通过控制器里面的一个元素来获取这个控制器的$scope var node=document.getElementById("NewsVote&quo ...

  6. HDU 1556 Color the ball(线段树:区间更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=1556 题意: N个气球,每次[a,b]之间的气球涂一次色,统计每个气球涂色的次数. 思路: 这道题目用树状数组和 ...

  7. mysql Alter 的问题

    转自:https://blog.csdn.net/c_enhui/article/details/50903351 -- 设置或删除列的默认值.该操作会直接修改.frm文件而不涉及表数据. 此操作很快 ...

  8. data.table 中的动态作用域

    data.table 中最常用的语法就是 data[i, j, by],其中 i.j 和 by 都是在动态作用域中被计算的.换句话说,我们不仅可以直接使用列,也可以提前定义诸如 .N ..I 和 .S ...

  9. USB.资料

    1.百度搜索 “usb java” 1.1.基于usb4java实现的java下的usb通信 - tomi_mint - 博客园.html(https://www.cnblogs.com/sowhat ...

  10. 【Python】模块学习之matplotlib柱状图、饼状图、动态图及解决中文显示问题

    前言 众所周知,通过数据绘图,我们可以将枯燥的数字转换成容易被人们接受的图表,从而让人留下更加深刻的印象.而大多数编程语言都有自己的绘图工具,matplotlib就是基于Python的绘图工具包,使用 ...