POJ3263 Tallest Cow 差分
题目描述
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.
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头牛的身高,和m对关系(a[i]与b[i]可以相互看见。即他们中间的牛都比他们矮)。已知最高的牛为第p头,身高为h,求每头牛的身高最大可能是多少。
因为我们要是每一头牛的身高尽量高,所以我们初始的时候设每一头牛的身高都为\(h\)
因为两头牛\(x,y\)之间可以相互看到,所以我们需要把区间\([x+1,y-1]\)内牛的身高都减去1
直接操作的话显然会T掉,所以我们可以用差分来维护
注意重复的操作要判断一下
代码
#include<cstdio>
#include<map>
#include<iostream>
#include<algorithm>
#include<utility>
using namespace std;
const int maxn=1e6+5;
map<pair<int,int>,bool> ma;
int d[maxn];
int main(){
int n,m,h,r;
scanf("%d%d%d%d",&n,&m,&h,&r);
for(int i=1;i<=r;i++){
int aa,bb;
scanf("%d%d",&aa,&bb);
if(aa>bb) swap(aa,bb);
if(ma[make_pair(aa,bb)]) continue;
d[aa+1]--,d[bb]++;
ma[make_pair(aa,bb)]=1;
}
for(int i=1;i<=n;i++){
d[i]+=d[i-1];
printf("%d\n",h+d[i]);
}
return 0;
}
POJ3263 Tallest Cow 差分的更多相关文章
- poj3263 Tallest Cow
题意略去. 考虑给定的R对pair(A, B). 即A能看见B,这意味着B不比A低,并且区间内部的所有元素的高度严格小于A的高度. 我们规定区间的方向:若A > B,为反方向,反之称为正方向. ...
- bzoj1635 / P2879 [USACO07JAN]区间统计Tallest Cow
P2879 [USACO07JAN]区间统计Tallest Cow 差分 对于每个限制$(l,r)$,我们建立一个差分数组$a[i]$ 使$a[l+1]--,a[r]++$,表示$(l,r)$区间内的 ...
- bzoj 1635: [Usaco2007 Jan]Tallest Cow 最高的牛——差分
Description FJ's N (1 <= N <= 10,000) cows conveniently indexed 1..N are standing in a line. E ...
- 【差分】Tallest Cow
题目 FJ's N(1≤N≤10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positive ...
- 【BZOJ】1635: [Usaco2007 Jan]Tallest Cow 最高的牛(差分序列)
http://www.lydsy.com/JudgeOnline/problem.php?id=1635 差分序列是个好东西啊....很多地方都用了啊,,, 线性的进行区间操作orz 有题可知 h[a ...
- [Luogu2879][USACO07JAN]区间统计Tallest Cow
题目描述 FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a p ...
- POJ 3263 Tallest Cow 题解
题目 FJ's \(N (1 ≤ N ≤ 10,000)\) cows conveniently indexed 1..N are standing in a line. Each cow has a ...
- BZOJ1635: [Usaco2007 Jan]Tallest Cow 最高的牛
1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 346 Solved: 184 ...
- BZOJ 1635: [Usaco2007 Jan]Tallest Cow 最高的牛
题目 1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec Memory Limit: 64 MB Description FJ's N ( ...
随机推荐
- 一个Redis查询案例
1.远程登陆进服务器 使用ssh连接至Linux服务器中 2.接入redis集群 redis-cli -h 10.1.8.12 -p 29000 3.执行查询命令 根据userid查询用户的最近在线时 ...
- Django如何上传图片并对上传图片进行访问
通过一个示例的完整演示过程,来学习django如何上传图片,以及对于media文件夹中的上传图片进行请求: 1.配置settings.py MEDIA_URL = '/media/' MEDIA_RO ...
- opencl(2)平台、设备、上下文的获取与信息获取
1:平台 1)获取平台id cl_int clGetPlatformIDs( cl_uint num_entries, //想要获取的平台数 cl_platform_id * flatfor ...
- 彻底搞懂 etcd 系列文章(三):etcd 集群运维部署
0 专辑概述 etcd 是云原生架构中重要的基础组件,由 CNCF 孵化托管.etcd 在微服务和 Kubernates 集群中不仅可以作为服务注册与发现,还可以作为 key-value 存储的中间件 ...
- DRY原则的一个简单实践
转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 原文出处:https://dzone.com/articles/dry-dont-repeat-yourse ...
- springboot使用自定义异常
sprinboot使用自定义注解 创建自定义异常类,继承RuntimeException public class MyException extends RuntimeException { p ...
- Java收徒,高级架构师关门弟子
最近感悟天命,偶有所得,故而打算收徒若干,以继吾之传承. 有缘者,可破瓶颈,走向架构师之峰,指日可待. 拜师要求: 1.工作经验:1年或以上. 2.入门费用:10000元(RMB). 联系方式(联系时 ...
- Arduino+sim800C家居安防火灾报警 拨打电话 发送短信例程程序
家居安防报警器,参考程序. 火灾报警 涉及用sim800c发短信,拨打电话通知. 接线: Sim800c 3.3V -> Arduino 3.3V Sim800c GND -> Ardui ...
- WPF入门(1)
开始对WPF动手,从0开始一步一步深入学习 1)参考文档:msdn.<WPF编程宝典:使用C#2012和NET 4.5 第4版> 2)开发工具:Microsoft Visual Studi ...
- 一分钟开始持续集成之旅系列之:C 语言 + Makefile
作者:CODING - 朱增辉 前言 make 工具非常强大,配合 makefile 文件可以实现软件的自动化构建,但是执行 make 命令依然需要经历手动输入执行.等待编译完成.将目标文件转移到合适 ...