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 ( ...
随机推荐
- github下载速度太慢,这里有已经下载完的nacos-server.zip组件
nacos: 分布式系统微服务的注册中心和配置中心 .. 在微服务系统中,起到很重要的作用.小伙伴老是给我抱怨,说这个github下面很慢慢,半天下载不下来,所有这样呢,我就把已经下载好的 nacos ...
- 2.3 sqlmap目录及结构
2.3 sqlmap目录及结构Tips:此篇文章主要参考了<sqlmap从入门到精通>这本书中的相关具体细节,由于这本书作者完成的时间大概在2017年作用,所以我根据书中提到的信息再根据目 ...
- 4-react 组件之间传值。
1.传值: 都是使用props和state结合得方式进行组件之间得传值 再react中传值得话是父子组件之间得传值,一般会把父组件中得state值通过props传给子组件,再子组件中使用props进行 ...
- [xDebug] PhpStorm Xdebug远程调试环境搭建
对于简单的工程,直接print_r();exit()已经足够,但是对于大型项目有时就有点力不从心.. 1,环境介绍 本地:windows10(192.168..)+ phpstorm8远程:Cento ...
- 讨论session共享方案设计
默认情况下,php的session文件是保存在磁盘文件中. 在php.ini配置文件中的配置项如下: session.save_handler = files session.save_path = ...
- <WP8开发学习笔记>获取手机的常用型号(如Lumia920,而非RM-822)
之前WP7时代可以用API获得WP手机的型号如lumia510,但是到了WP8后用APi只能获得硬件版本号了如RM-822,这种型号可以让我们更详细的了解具体的硬件版本,比如国行和港行,设备版本号不一 ...
- 使用JFreeChart生成条形图
1. 准备工作 下载JFreeChart,我使用的版本为1.0.19,相关内容参见JFreeChart,下载链接为https://sourceforge.net/projects/jfreechart ...
- 破解版BrupSuite安装及其问题解决及环境部署
一 下载 BrupSuite_pro_v1.7.37的压缩包百度网盘链接: https://pan.baidu.com/s/1KkuseybjpuHo-6V4_wh9vw 提取码: 3vcs 说明一下 ...
- 【JMeter_21】JMeter逻辑控制器__模块控制器<Module Controller>
模块控制器<Module Controller> 业务逻辑: 可以理解为引用.调用的意思,执行内容为Module To Run种所选的内容,引用范围为当前测试计划内的测试片段.逻辑控制器& ...
- JVM生命周期与运行过程
1. Java虚拟机的生命周期 Java虚拟机的生命周期 一个运行中的Java虚拟机有着一个清晰的任务:执行Java程序.程序开始执行时他才运行,程序结束时他就停止.你在同一台机器上运行三个程序,就会 ...