• [HDOJ6119] 小小粉丝度度熊(尺取)


    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6119

    合并有重叠的段后尺取。

     1 /*
     2 ━━━━━┒ギリギリ♂ eye!
     3 ┓┏┓┏┓┃キリキリ♂ mind!
     4 ┛┗┛┗┛┃\○/
     5 ┓┏┓┏┓┃ /
     6 ┛┗┛┗┛┃ノ)
     7 ┓┏┓┏┓┃
     8 ┛┗┛┗┛┃
     9 ┓┏┓┏┓┃
    10 ┛┗┛┗┛┃
    11 ┓┏┓┏┓┃
    12 ┛┗┛┗┛┃
    13 ┓┏┓┏┓┃
    14 ┃┃┃┃┃┃
    15 ┻┻┻┻┻┻
    16 */
    17 #include <bits/stdc++.h>
    18 using namespace std;
    19 #define fr first
    20 #define sc second
    21 #define cl clear
    22 #define BUG puts("here!!!")
    23 #define W(a) while(a--)
    24 #define pb(a) push_back(a)
    25 #define Rint(a) scanf("%d", &a)
    26 #define Rll(a) scanf("%I64d", &a)
    27 #define Rs(a) scanf("%s", a)
    28 #define Cin(a) cin >> a
    29 #define FRead() freopen("in", "r", stdin)
    30 #define FWrite() freopen("out", "w", stdout)
    31 #define Rep(i, len) for(int i = 0; i < (len); i++)
    32 #define For(i, a, len) for(int i = (a); i < (len); i++)
    33 #define Cls(a) memset((a), 0, sizeof(a))
    34 #define Clr(a, x) memset((a), (x), sizeof(a))
    35 #define Full(a) memset((a), 0x7f7f7f, sizeof(a))
    36 #define lrt rt << 1
    37 #define rrt rt << 1 | 1
    38 #define pi 3.14159265359
    39 #define RT return
    40 #define lowbit(x) x & (-x)
    41 #define onenum(x) __builtin_popcount(x)
    42 typedef long long LL;
    43 typedef long double LD;
    44 typedef unsigned long long ULL;
    45 typedef pair<int, int> pii;
    46 typedef pair<string, int> psi;
    47 typedef pair<LL, LL> pll;
    48 typedef map<string, int> msi;
    49 typedef vector<int> vi;
    50 typedef vector<LL> vl;
    51 typedef vector<vl> vvl;
    52 typedef vector<bool> vb;
    53 
    54 const int maxn = 100100;
    55 int n;
    56 LL m;
    57 pll seg[maxn];
    58 
    59 signed main() {
    60     // freopen("in", "r", stdin);
    61     while(~Rint(n)) {
    62         Rll(m);
    63         For(i, 1, n+1) {
    64             Rll(seg[i].first);
    65             Rll(seg[i].second);
    66         }
    67         sort(seg+1, seg+n+1);
    68         int tn = n;
    69         n = 0;
    70         For(i, 1, tn+1) {
    71             if(i != 1 && seg[i].first <= seg[n].second) {
    72                 seg[n].second = max(seg[n].second, seg[i].second);
    73             }
    74             else seg[++n] = seg[i];
    75         }
    76         int lo = 1;
    77         LL cur = 0, ret = 0;
    78         For(i, 1, n+1) {
    79             if(i != 1) {
    80                 cur += seg[i].first - seg[i-1].second - 1;
    81             }
    82             while(i != 1 && cur > m) {
    83                 cur -= seg[lo+1].first - seg[lo].second - 1;
    84                 lo++;
    85             }
    86             ret = max(ret, seg[i].second - seg[lo].first + 1 + m - cur);
    87         }
    88         printf("%I64d
    ", ret);
    89     }
    90     return 0;
    91 }
  • 相关阅读:
    Delphi编程技巧大全 FMX
    delphi try 抛出异常消息
    SQL Server查询代码在哪个视图、存储过程、函数、触发中使用过
    小米11如何打开“开发者选项”和“USB调试”图文教程
    SQL Server获取表结构信息(字段名、类型、长度、精度、小数位数、主键、自动增长)
    SQL Server读取表结构到变量中
    如何使用 GitHub?
    Delphi D10.X VCL和FireMonkey之间的常见差异介绍
    idea每次新建项目都要重新配置maven的解决方案
    【转】Linux系统产生随机数的6种方法
  • 原文地址:https://www.cnblogs.com/kirai/p/7389025.html
Copyright © 2020-2023  润新知