hdu 6119/2017百度之星初赛B——小小粉丝度度熊(尺取/贪心)

来源:互联网 发布:福州云顶网络智联 编辑:程序博客网 时间:2024/05/29 14:55

小小粉丝度度熊

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1317    Accepted Submission(s): 424


Problem Description
度度熊喜欢着喵哈哈村的大明星——星星小姐。

为什么度度熊会喜欢星星小姐呢?

首先星星小姐笑起来非常动人,其次星星小姐唱歌也非常好听。

但这都不是最重要的,最重要的是,星星小姐拍的一手好代码!

于是度度熊关注了星星小姐的贴吧。

一开始度度熊决定每天都在星星小姐的贴吧里面签到。

但是度度熊是一个非常健忘的孩子,总有那么几天,度度熊忘记签到,于是就断掉了他的连续签到。

不过度度熊并不是非常悲伤,因为他有m张补签卡,每一张补签卡可以使得某一忘签到的天,变成签到的状态。

那么问题来了,在使用最多m张补签卡的情况下,度度熊最多连续签到多少天呢?

 

Input
本题包含若干组测试数据。

第一行两个整数n,m,表示有n个区间,这n个区间内的天数,度度熊都签到了;m表示m张补签卡。

接下来n行,每行两个整数(l[i],r[i]),表示度度熊从第l[i]天到第r[i]天,都进行了签到操作。


数据范围:

1<=n<=100000

0<=m<=1000000000
0<=l[i]<=r[i]<=1000000000


注意,区间可能存在交叉的情况。
 

Output
输出度度熊最多连续签到多少天。
 

Sample Input
2 11 13 31 21 1
 

Sample Output
33
Hint
样例一:度度熊补签第2天,然后第1天、第二天和第三天都进行了签到操作。样例二:度度熊补签第2天和第3天。
 

Source
2017"百度之星"程序设计大赛 - 初赛(B)
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6119 6118 6117 6116 6115 
 

Statistic | Submit | Discuss | Note

题意:给你n个人区间 可能重合包含 给你m次机会每次可以填补一个点 求最大连续长度

思路:数据量较大 但是把区间处理后发现 符合双指针的连续性

注意:处理连续重合区间

#include <iostream>#include <algorithm>#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <string.h>#include <map>#include <set>#include <queue>#include <deque>#include <list>#include <bitset>#include <stack>#include <stdlib.h>#define lowbit(x) (x&-x)#define e exp(1.0)const int mod=1e9+7;const int inf=0x3f3f3f;//ios::sync_with_stdio(false);//    auto start = clock();//    cout << (clock() - start) / (double)CLOCKS_PER_SEC;typedef long long ll;typedef long long LL;using namespace std;/*                    _ooOoo_                   o8888888o                   88" . "88                   (| -_- |)                   O\  =  /O                ____/`---'\____              .'  \\|     |//  `.             /  \\|||  :  |||//  \            /  _||||| -:- |||||-  \            |   | \\\  -  /// |   |            | \_|  ''\---/''  |   |            \  .-\__  `-`  ___/-. /           ___`. .'  /--.--\  `. . __        ."" '<  `.___\_<|>_/___.'  >'"".       | | :  `- \`.;`\ _ /`;.`/ - ` : | |       \  \ `-.   \_ __\ /__ _/   .-` /  /  ======`-.____`-.___\_____/___.-`____.-'======                     `=---='  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                 pass System Test! */const int maxn=2e5+10;pair<ll,ll>p[maxn];ll sum[maxn];ll n,m;int main(){    ios::sync_with_stdio(false);    while(cin>>n>>m)    {        for(int i=0;i<n;i++)        {            ll l,r;            cin>>l>>r;            p[i]=make_pair(l,r);        }        sort(p,p+n);        int cnt=0;        for(int i=0;i<n;i++)        {            ll l=i,r=i+1,last=p[i].second;            while(r<n && p[r].first<=last)            {                last=max(last,p[r].second);                r++;            }            r--;            p[cnt++]=make_pair(p[l].first,last);            i=r;        }        sum[0]=0;        for(int i=1;i<cnt;i++)            sum[i]=sum[i-1]+p[i].first-p[i-1].second-1;        ll ans=m;        int r=0;        for(int l=0;r<cnt&&l<cnt;l++)        {            while(sum[r]-sum[l]<=m && r<cnt)                r++;            ll x=m-(sum[r-1]-sum[l]);            ans=max(ans,p[r-1].second-p[l].first+1+x);        }        cout<<ans<<endl;    }    return 0;}


阅读全文
0 0