bzoj 1635: [Usaco2007 Jan]Tallest Cow 最高的牛
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
Sample Output
输出每头牛可能的最高高度
第一行四个数分别表示有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 最高的牛相关推荐
- 1635: [Usaco2007 Jan]Tallest Cow 最高的牛
1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 383 Solved: 21 ...
- [BZOJ1635][Usaco2007 Jan]Tallest Cow 最高的牛
1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 656 Solved: 40 ...
- [BZOJ] 1634: [Usaco2007 Jan]Protecting the Flowers 护花
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 827 S ...
- BZOJ 1613: [Usaco2007 Jan]Running贝茜的晨练计划
题目 1613: [Usaco2007 Jan]Running贝茜的晨练计划 Time Limit: 5 Sec Memory Limit: 64 MB Description 奶牛们打算通过锻炼来 ...
- 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 & ...
- [BZOJ] 1614: [Usaco2007 Jan]Telephone Lines架设电话线
1614: [Usaco2007 Jan]Telephone Lines架设电话线 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 1806 Solve ...
- 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 ...
- bzoj 1634: [Usaco2007 Jan]Protecting the Flowers 护花(贪心排序)
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 824 S ...
- bzoj 1614: [Usaco2007 Jan]Telephone Lines架设电话线(二分+SPFA)
1614: [Usaco2007 Jan]Telephone Lines架设电话线 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 1761 Solve ...
最新文章
- Docker 入门系列(7)- Dockerfile 使用(FROM、RUN、CMD、EXPOSE、ENV、ADD、COPY、ENTRYPOINT、VOLUME、WORKDIR)
- 创建型模式之Builder模式
- matlab计算每个细胞面积,手把手教你用 Imaris 计算细胞面积
- 技术干货 | 阿里云数据库PostgreSQL 13大版本揭秘
- 15.10.4 捕获异常
- css设置一个div显示在另一个div的上层_CSS工程中常见问题-1
- 在Spring MVC中使用Velocity
- .NET 中 async 和 await
- hbase 命令_HBase原理与实践 | 生产环境上线前真的优化过吗?
- 百度页面的html5结构,HTML5+CSS3网站设计基础教程
- jquery替换节点
- java 关闭对话框_java等待关闭对话框
- QT添加资源文件并使用
- QCC3003x BLE 设置私有地址
- 实现内外网互通-概述
- 如何将网页保存为pdf
- matplotlib绘制鼠标的十字光标(自定义方式,官方实例)
- linux服务器如何查看硬盘型号,Linux如何查看硬盘型号和缓存
- 51单片机向PC端发送字符
- 目标检测 | YOLO系列超全讲解v1,v2,v3