zoukankan      html  css  js  c++  java
  • BZOJ1635: [Usaco2007 Jan]Tallest Cow 最高的牛

    n<=10000个人,第L个人最高,所有人最高高度H,r个关系表示Ai能看到Bi,也就是,Ai到Bi中间的人都比Ai和Bi矮且Bi不比Ai矮,求每个人最高的可能高度,保证有解。

    不知道这个L是来搞笑还是干嘛的

    假设一开始所有人最高,一个关系就把Ai到Bi间的点做区间减1,最后单点查询,差分下即可。

    唯一的坑点是可能有重复描述,记得去个重!

     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<stdlib.h>
     4 #include<algorithm>
     5 //#include<assert.h>
     6 #include<math.h>
     7 //#include<iostream>
     8 using namespace std;
     9 
    10 int n,h,r;
    11 #define maxn 10011
    12 int cha[maxn];
    13 struct Mes
    14 {
    15     int x,y;
    16     bool operator < (const Mes &b) const {return x<b.x || (x==b.x && y<b.y);}
    17     bool operator == (const Mes &b) const {return x==b.x && y==b.y;}
    18 }mes[maxn];
    19 int main()
    20 {
    21     int x;
    22     scanf("%d%d%d%d",&n,&x,&h,&r);
    23     for (int i=1;i<=r;i++)
    24     {
    25         scanf("%d%d",&mes[i].x,&mes[i].y);
    26         if (mes[i].x>mes[i].y) swap(mes[i].x,mes[i].y);
    27     }
    28     sort(mes+1,mes+1+r);
    29     r=unique(mes+1,mes+1+r)-mes-1;
    30     memset(cha,0,sizeof(cha));
    31     for (int i=1;i<=r;i++) cha[mes[i].x+1]--,cha[mes[i].y]++;
    32 //    for (int i=1;i<=n;i++) cout<<cha[i]<<' ';cout<<endl;
    33     x=0;for (int i=1;i<=n;i++) x+=cha[i],printf("%d
    ",h+x);
    34     return 0;
    35 }
    View Code
  • 相关阅读:
    spring-boot 访问时,加与不加项目名分析
    关于文章
    随笔
    工作小结五
    《文章翻译》PCA&SVD
    工作小结四
    工作小结三
    从零开始实现SSD目标检测(pytorch)(一)
    工作小结二
    《论文翻译》 GIOU
  • 原文地址:https://www.cnblogs.com/Blue233333/p/7665659.html
Copyright © 2011-2022 走看看