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 ...
随机推荐
- iOS -- Effective Objective-C 阅读笔记 (2)
1: 多用类型常量, 少用 #define 预处理指令 #define 预处理指令会把碰到的所有 指定名称 一律换位 定义的内容, 这样的话, 假设此指令在某个头文件中, 那么所有引入这个头文件的代码 ...
- Confluence 6 附件存储文件系统的分级
从 Confluence 3.0 开始,附件的存储方式有了重大的改变和升级.如果你是从 Confluence 2.10 及其早期版本升级上来的,请参考 Upgrading Confluence 页面中 ...
- python - 发送带各种类型附件的邮件
如何发送各种类型的附件. 基本思路就是,使用MIMEMultipart来标示这个邮件是多个部分组成的,然后attach各个部分.如果是附件,则add_header加入附件的声明. 在python中,M ...
- spring 容器的基础 XmlBeanFactory
Spring容器最核心的两个类 DefaultListableBeanFactory 与 XmlBeanDefinitionReader ,XmlBeanFactory继承自DefaultLista ...
- LeetCode(112):路径总和
Easy! 题目描述: 给定一个二叉树和一个目标和,判断该树中是否存在根节点到叶子节点的路径,这条路径上所有节点值相加等于目标和. 说明: 叶子节点是指没有子节点的节点. 示例: 给定如下二叉树,以及 ...
- HTML 转义字符对应表
<%@ tag language="java" pageEncoding="UTF-8" %> <%@ attribute name=&quo ...
- Winhex数据恢复学习笔记(四)
睡不着,那就深夜写篇笔记打发一下不瞌睡,❥(^_-) 1.winhex在文件批量处理上主要是针对批量保存.打开.关闭,主要还是基于批量打开的其他一些操作,这里通过构造通配符来批量打开,列如 *符号 ? ...
- PHP 方法,类与对象的相关函数学习
1.function_exists function_exists(string)检测函数是否存在,string表示需要检测的函数名称(注意与property_exists,method_exists ...
- node.js 的页面渲染方法ejs
.安装依赖的组件 npm i consolidate -D npm i ejs -D 2.布局服务端 const express = require('express'); const consoli ...
- Linux基础三:linux目录结构和目录文件的浏览、管理及维护
目录文件的浏览.管理及维护(一) 1.Linux文件系统的层次结构 1)Linux文件系统的树状结构:在Linux或UNIX操作系统中,所有的文件和目录都被组织成一个以根节点开始的倒置的树状结构. 2 ...