Tallest Cow POJ - 3263 (区间点修改)
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
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
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
然后有r个关系 说明这个关系中的两头牛相互看的见(他们中间的牛高度比他们矮)
求所有牛最大可能的高度 思路:
1、既然给出每个关系中x、y两头牛相互可以看见,那么他们之间的牛的高度肯定比他要矮,所以每次给出x、y,我们只需要将x+1到y-1的牛高度全部-1,这样最后就知道了他们之间的最小高度差,
再把每个cow【i】+h O(NR)
2、我们可以优化一下,就是说给你x、y两头牛,你在x+1的位置-1,再y的位置+1,这样我们就记录了这个关系,你从x遍历到y,让cow【i】+=cow【i-1】,你会发现,他每个x+1到y-1都是-1而x、y则是0,
我们可以把所有的关系先记录下来,然后遍历就可以知道他们之间的最小高度差,然后cow【i】+h O(N+R) 坑点:记得去重
#include<cstdio>
#include<iostream>
#include<map>
using namespace std;
typedef pair<int,int> P;
const int maxn = 1e4+;
int n,i,h,r;
int ans[maxn];
map<P,int>mp;
int main()
{
scanf("%d%d%d%d",&n,&i,&h,&r);
for(int i=;i<=r;i++)
{
int x,y;
scanf("%d%d",&x,&y);
if(x > y)swap(x,y);
if(mp[P(x,y)])continue;
mp[P(x,y)]=;
for(int j=x+;j<y;j++)
{
ans[j]--;
} }
for(int i=;i<=n;i++)
{
printf("%d\n",ans[i]+h);
}
}
#include<cstdio>
#include<iostream>
#include<map>
using namespace std;
typedef pair<int,int> P;
const int maxn = 1e4+;
int n,i,h,r;
int ans[maxn];
map<P,int>mp;
int main()
{
scanf("%d%d%d%d",&n,&i,&h,&r);
for(int i=;i<=r;i++)
{
int x,y;
scanf("%d%d",&x,&y);
if(x > y)swap(x,y);
if(mp[P(x,y)])continue;
mp[P(x,y)]=;
ans[x+]--;
ans[y]++;
}
for(int i=;i<=n;i++)
{
ans[i] += ans[i-];
printf("%d\n",ans[i]+h);
}
}
Tallest Cow POJ - 3263 (区间点修改)的更多相关文章
- 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 ...
- poj 3263 Tallest Cow(线段树)
Language: Default Tallest Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1964 Ac ...
- 洛谷P2879 [USACO07JAN]区间统计Tallest Cow
To 洛谷.2879 区间统计 题目描述 FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..N are standing in a line. ...
- bzoj1635 / P2879 [USACO07JAN]区间统计Tallest Cow
P2879 [USACO07JAN]区间统计Tallest Cow 差分 对于每个限制$(l,r)$,我们建立一个差分数组$a[i]$ 使$a[l+1]--,a[r]++$,表示$(l,r)$区间内的 ...
- [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 ...
- poj3263 Tallest Cow
题意略去. 考虑给定的R对pair(A, B). 即A能看见B,这意味着B不比A低,并且区间内部的所有元素的高度严格小于A的高度. 我们规定区间的方向:若A > B,为反方向,反之称为正方向. ...
- POJ 3264 区间最大最小值Sparse_Table算法
题目链接:http://poj.org/problem?id=3264 Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total ...
- poj 3264 区间最大最小值 RMQ问题之Sparse_Table算法
Balanced Lineup Time Limit: 5000 MS Memory Limit: 0 KB 64-bit integer IO format: %I64d , %I64u Java ...
- 【BZOJ】1635: [Usaco2007 Jan]Tallest Cow 最高的牛(差分序列)
http://www.lydsy.com/JudgeOnline/problem.php?id=1635 差分序列是个好东西啊....很多地方都用了啊,,, 线性的进行区间操作orz 有题可知 h[a ...
随机推荐
- 计算机信息类ComputerInfo(车)
using System; using System.Management; using System.Net; using System.Net.Sockets; using System.Text ...
- Confluence 6 数据中心的 SAML 单点登录最佳实践和故障排除
最佳实践 SAML 授权仅仅在有限的时间进行校验.你需要确定运行你的应用的计算机时间与 IdP 的时间是同步的. 如果你应用中的用户和用户组是通过用户目录进行配置的,你通常希望用户来源目录和你的 Id ...
- 以resnet作为前置网络的ssd目标提取检测
http://blog.csdn.net/zhangjunbob/article/details/53119959
- Android 框架 Afinal使用
介绍android Afinal框架功能: Afinal是一个开源的android的orm和ioc应用开发框架.在android应用开发中,通过Afinal的ioc框架,诸如UI绑定,事件绑定,通过注 ...
- springboot快速使用
1.编写SpringConfig 用于实例化Spring容器 @Configuration //通过该注解来表明该类是一个Spring的配置,相当于一个xml文件 @Bean // 通过该注解来表明是 ...
- 谷歌浏览器Software Reporter Tool长时间占用CPU解决办法
什么是Software Reporter Tool Software Reporter Tool是一个Chrome清理工具,用于清理谷歌浏览器中不必要或恶意的扩展,应用程序,劫持开始页面等等.当你安装 ...
- C#学习-析构函数
析构函数用于在类销毁之前释放类实例所使用的托管和非托管资源. 对于C#应用程序所创建的大多数对象,可以依靠.NET Framework的垃圾回收器(GC)来隐式地执行内存管理任务. 但是,若创建封装了 ...
- 解决Python安装模块出错 ImportError: No module named setuptools
1.下载ez_setup.py文件 下载地址:https://bootstrap.pypa.io/ez_setup.py 百度地址:http://pan.baidu.com/s/1jIgMO9w 2. ...
- [转] JavaScript设计模式之发布-订阅模式(观察者模式)-Part1
<JavaScript设计模式与开发实践>读书笔记. 发布-订阅模式又叫观察者模式,它定义了对象之间的一种一对多的依赖关系.当一个对象的状态发生改变时,所有依赖它的对象都将得到通知. 例如 ...
- Tarjan算法【强连通分量】
转自:byvoid:有向图强连通分量的Tarjan算法 Tarjan算法是基于对图深度优先搜索的算法,每个强连通分量为搜索树中的一棵子树.搜索时,把当前搜索树中未处理的节点加入一个堆栈,回溯时可以判断 ...