Description

FJ's N (1 <= N <= 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positive integer height (which is a bit of secret). You are told only the height H (1 <= H <= 1,000,000) of the tallest cow along with the index I of that cow. FJ has made a list of R (0 <= R <= 10,000) lines of the form "cow 17 sees cow 34". This means that cow 34 is at least as tall as cow 17, and that every cow between 17 and 34 has a height that is strictly smaller than that of cow 17. For each cow from 1..N, determine its maximum possible height, such that all of the information given is still correct. It is guaranteed that it is possible to satisfy all the constraints.

有n(1 <= n <= 10000)头牛从1到n线性排列,每头牛的高度为h[i](1 <= i <= n),现在告诉你这里面的牛的最大高度为maxH,而且有r组关系,每组关系输入两个数字,假设为a和b,表示第a头牛能看到第b头牛,能看到的条件是a, b之间的其它牛的高度都严格小于min(h[a], h[b]),而h[b] >= h[a]

Input

* Line 1: Four space-separated integers: N, I, H and R

* Lines 2..R+1: Two distinct space-separated integers A and B (1 <= A, B <= N), indicating that cow A can see cow B.

Output

* Lines 1..N: Line i contains the maximum possible height of cow i.

Sample Input

9 3 5 5
1 3
5 3
4 3
3 7
9 8

INPUT DETAILS:

There are 9 cows, and the 3rd is the tallest with height 5.

Sample Output

5
4
5
3
4
4
5
5
5
————————————————————————————
这道题 差分就可以辣 a b 之间的数明显起码要比a b小1 
然后差分一下用max-前缀和就可以辣 不过这题数据有毒.... 他可以出现多组 a b
  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. using std::swap;
  5. const int M=2e4+;
  6. int read(){
  7. int ans=,f=,c=getchar();
  8. while(c<''||c>''){if(c=='-') f=-; c=getchar();}
  9. while(c>=''&&c<=''){ans=ans*+(c-''); c=getchar();}
  10. return ans*f;
  11. }
  12. int n,h,m,now;
  13. int f[M],x,y;
  14. struct pos{int x,y;}q[M];
  15. bool cmp(pos a,pos b){return a.x!=b.x?a.x<b.x:a.y<b.y;}
  16. int main(){
  17. n=read(); read(); h=read(); m=read();
  18. for(int i=;i<=m;i++){
  19. x=read(); y=read();
  20. if(x>y) swap(x,y);
  21. q[i].x=x; q[i].y=y;
  22. }std::sort(q+,q++m,cmp);
  23. for(int i=;i<=m;i++){
  24. if(q[i].x==q[i-].x&&q[i].y==q[i-].y) continue;
  25. f[q[i].x+]--; f[q[i].y]++;
  26. }
  27. for(int i=;i<=n;i++){
  28. now+=f[i];
  29. printf("%d\n",h+now);
  30. }
  31. return ;
  32. }

bzoj 1635: [Usaco2007 Jan]Tallest Cow 最高的牛——差分的更多相关文章

  1. BZOJ 1635: [Usaco2007 Jan]Tallest Cow 最高的牛

    题目 1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec  Memory Limit: 64 MB Description FJ's N ( ...

  2. bzoj 1635: [Usaco2007 Jan]Tallest Cow 最高的牛【差分】

    s[i]为差分后的"i这头牛前有几头比它高",计算答案的时候加成前缀和,假设第一头最高减一下即可 用map记录一下被加过的区间,避免重复 #include<iostream& ...

  3. 1635: [Usaco2007 Jan]Tallest Cow 最高的牛

    1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 383  Solved: 211 ...

  4. 【BZOJ】1635: [Usaco2007 Jan]Tallest Cow 最高的牛(差分序列)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1635 差分序列是个好东西啊....很多地方都用了啊,,, 线性的进行区间操作orz 有题可知 h[a ...

  5. 【BZOJ】1635: [Usaco2007 Jan]Tallest Cow 最高的牛

    [题意]n头牛,其中最高h.给定r组关系a和b,要求满足h[b]>=h[a]且a.b之间都小于min(h[a],h[b]),求第i头牛可能的最高高度. [算法]差分 [题解]容易发现r组关系只能 ...

  6. BZOJ1635: [Usaco2007 Jan]Tallest Cow 最高的牛

    1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 346  Solved: 184 ...

  7. bzoj 1701 [Usaco2007 Jan]Cow School牛学校

    [Usaco2007 Jan]Cow School牛学校 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 175  Solved: 83[Submit][S ...

  8. bzoj 1636: [Usaco2007 Jan]Balanced Lineup -- 线段树

    1636: [Usaco2007 Jan]Balanced Lineup Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 772  Solved: 560线 ...

  9. BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花( 贪心 )

    考虑相邻的两头奶牛 a , b , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...

随机推荐

  1. 计算器软件实现系列(五)策略模式+asp.net

    一 策略模式代码的编写 using System; using System.Collections.Generic; using System.Linq; using System.Web; /// ...

  2. 模拟Excel同一列相同值的单元格合并

    背景 项目中有一个查询工作量,可以将查询的结果导出到Excel表中.在Excel工具中,有一个合并居中功能,可以将选中的单元格合并成一个大的单元格.现在需要在程序中直接实现查询结果的汇总, 问题分析 ...

  3. <Effective C++>读书摘要--Templates and Generic Programming<一>

    1.The initial motivation for C++ templates was straightforward: to make it possible to create type-s ...

  4. python redis插件安装

    #tar xvzf redis-py-2.2.1.tar.gz #cd redis-py-2.2.1 #python setup.py install   附件: https://app.yinxia ...

  5. JSTL标签之核心标签

    JSTL(JSP Standard Tag Library ,JSP标准标签库)是一个实现 Web应用程序中常见的通用功能的定制标记库集,这些功能包括迭代和条件判断.数据管理格式化.XML 操作以及数 ...

  6. 第68天:原型prototype方法

    一.原型prototype方法声明 构造函数有一个prototype属性,指向实例对象的原型对象.通过同一个构造函数实例化的多个对象具有相同的原型对象.经常使用原型对象来实现继承 <!DOCTY ...

  7. hdu2295-Radar

    有n个城市,\(m\)个雷达,\(k\)个操作员,每个操作员只能操作一个雷达.每个雷达的覆盖范围是一个以雷达坐标为中心的圆,所有雷达的覆盖半径是相同的. 现在给出这\(n\)个城市,\(m\)个雷达的 ...

  8. BZOJ5288 & 洛谷4436 & LOJ2508:[HNOI/AHOI2018]游戏——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=5288 https://www.luogu.org/problemnew/show/P4436 ht ...

  9. [bzoj] 1030 文本生成器 || AC自动机+dp

    原题 给出n个字符串,求随机生成一个m长度的字符串,有多少个是可辨识的(即出现了n个字符串中的任意字符串) 正难则反 求有多少个不可辨识的,26^m-不可辨识即为答案 f[i][j]表示填到第i个字符 ...

  10. HDOJ(HDU).2191. 悼念512汶川大地震遇难同胞――珍惜现在,感恩生活 (DP 多重背包+二进制优化)

    HDOJ(HDU).2191. 悼念512汶川大地震遇难同胞――珍惜现在,感恩生活 (DP 多重背包+二进制优化) 题意分析 首先C表示测试数据的组数,然后给出经费的金额和大米的种类.接着是每袋大米的 ...