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

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 647  Solved: 396
[Submit][Status][Discuss]

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

Sample Output

5
4
5
3
4
4
5
5
5

输出每头牛可能的最高高度

第一行四个数分别表示有n头牛,第i头牛最高,高度为h,总共有m对关系

如果一头牛被包在k个范围内,那么这头牛的高度就是h-k,所以可以统计一下前缀和

对于关系(x, y),若x>y则交换,然后cnt[x+1]--, cnt[y]++,不过注意判重!

#include<stdio.h>
#include<algorithm>
using namespace std;
typedef struct Cow
{int x;int y;bool operator < (const Cow &b) const{if(x<b.x || x==b.x && y<b.y)return 1;return 0;}
}Cow;
Cow s[10005];
int cnt[10005];
int main(void)
{int sum, n, h, m, i;scanf("%d%*d%d%d", &n, &h, &m);for(i=1;i<=m;i++){scanf("%d%d", &s[i].x, &s[i].y);if(s[i].x>s[i].y)swap(s[i].x, s[i].y);}sort(s+1, s+m+1);for(i=1;i<=m;i++){if(s[i].x==s[i-1].x && s[i].y==s[i-1].y)continue;cnt[s[i].x+1]--, cnt[s[i].y]++;}sum = h;for(i=1;i<=n;i++){sum += cnt[i];printf("%d\n", sum);}return 0;
}

bzoj 1635: [Usaco2007 Jan]Tallest Cow 最高的牛相关推荐

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

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

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

    1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 656  Solved: 40 ...

  3. [BZOJ] 1634: [Usaco2007 Jan]Protecting the Flowers 护花

    1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 827  S ...

  4. BZOJ 1613: [Usaco2007 Jan]Running贝茜的晨练计划

    题目 1613: [Usaco2007 Jan]Running贝茜的晨练计划 Time Limit: 5 Sec  Memory Limit: 64 MB Description 奶牛们打算通过锻炼来 ...

  5. bzoj 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会 -- Tarjan

    1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会 Time Limit: 5 Sec  Memory Limit: 64 MB Description The N (2 & ...

  6. [BZOJ] 1614: [Usaco2007 Jan]Telephone Lines架设电话线

    1614: [Usaco2007 Jan]Telephone Lines架设电话线 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 1806  Solve ...

  7. bzoj 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会(Trajan)

    1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 380  Solved: 2 ...

  8. bzoj 1634: [Usaco2007 Jan]Protecting the Flowers 护花(贪心排序)

    1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 824  S ...

  9. bzoj 1614: [Usaco2007 Jan]Telephone Lines架设电话线(二分+SPFA)

    1614: [Usaco2007 Jan]Telephone Lines架设电话线 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 1761  Solve ...

最新文章

  1. Docker 入门系列(7)- Dockerfile 使用(FROM、RUN、CMD、EXPOSE、ENV、ADD、COPY、ENTRYPOINT、VOLUME、WORKDIR)
  2. 创建型模式之Builder模式
  3. matlab计算每个细胞面积,手把手教你用 Imaris 计算细胞面积
  4. 技术干货 | 阿里云数据库PostgreSQL 13大版本揭秘
  5. 15.10.4 捕获异常
  6. css设置一个div显示在另一个div的上层_CSS工程中常见问题-1
  7. 在Spring MVC中使用Velocity
  8. .NET 中 async 和 await
  9. hbase 命令_HBase原理与实践 | 生产环境上线前真的优化过吗?
  10. 百度页面的html5结构,HTML5+CSS3网站设计基础教程
  11. jquery替换节点
  12. java 关闭对话框_java等待关闭对话框
  13. QT添加资源文件并使用
  14. QCC3003x BLE 设置私有地址
  15. 实现内外网互通-概述
  16. 如何将网页保存为pdf
  17. matplotlib绘制鼠标的十字光标(自定义方式,官方实例)
  18. linux服务器如何查看硬盘型号,Linux如何查看硬盘型号和缓存
  19. 51单片机向PC端发送字符
  20. 目标检测 | YOLO系列超全讲解v1,v2,v3

热门文章

  1. python刚出来多少薪资-2019 年Python工程师的平均薪资是多少?
  2. python网课哪个好-python网课学习笔记--4
  3. 自从微信更新后,广东人都玩疯了!以后语音可以识别英语、粤语啦!
  4. 语音识别相关书籍抖音十大先看哪一本最好
  5. 利用MATLAB平台实现字的语音识别功能
  6. 2020最常用的8个代码编辑器推荐
  7. 三种水平居中布局~详细
  8. 无限极分类php简单,创建无限极分类树型结构的简单方法
  9. respond是空的_httpClient 获取response 中的 content 为空的原因(急求)
  10. 【堆】Leetcode692:前k个高频单词