【差分】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
分析
因为让求的是每头牛最高多少,我们先假设每头牛都是最高的,然后输入两个数a,b,表示两个数中的每头牛比两边的小,所以就把从a+1到b-1的牛高度-1;这个题数据范围1e4,可以用差分优化,然后就完了。
代码
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e4+;
int n,m,g,h,a[maxn];
bool v[maxn][maxn];
int main() {
scanf("%d%d%d%d", &n, &h, &g, &m);
for(int i = ; i <= m; i++) {
int x, y;
scanf("%d%d", &x, &y);
if (x > y) swap(x, y);
if (v[x][y]) continue;
v[x][y] = ;
a[x+]--,a[y]++;
}
for(int i = ; i <= n; i++)
a[i] += a[i-], printf("%d\n", a[i] + g);
return ;
}
【差分】Tallest Cow的更多相关文章
- 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 ...
- POJ3263 Tallest Cow 差分
题目描述 FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a p ...
- 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 最高的牛(差分序列)
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 ( ...
- 1635: [Usaco2007 Jan]Tallest Cow 最高的牛
1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 383 Solved: 211 ...
随机推荐
- Java实现 LeetCode 713 乘积小于K的子数组(子集数量+双指针)
713. 乘积小于K的子数组 给定一个正整数数组 nums. 找出该数组内乘积小于 k 的连续的子数组的个数. 示例 1: 输入: nums = [10,5,2,6], k = 100 输出: 8 解 ...
- Java实现最近点问题
**问题描述:** 给定某空间中(直线空间或平面空间)n个点,请找出它们中的最近点对.你需要完成下列任务: 1.随机产生或手工输入n个点的坐标. 2.输出最近的两个点的坐标. 3.算法尽可能效率高. ...
- Java实现合并排序
1 问题描述 给定一组数据,使用合并排序得到这组数据的非降序排列. 2 解决方案 2.1 合并排序原理简介 引用自百度百科: 合并排序是建立在归并操作上的一种有效的排序算法.该算法是采用分治法(Div ...
- Java实现第八届蓝桥杯分巧克力
分巧克力 题目描述 儿童节那天有K位小朋友到小明家做客.小明拿出了珍藏的巧克力招待小朋友们. 小明一共有N块巧克力,其中第i块是Hi x Wi的方格组成的长方形. 为了公平起见,小明需要从这 N 块巧 ...
- java实现第四届蓝桥杯猜年龄
猜年龄 题目描述 美国数学家维纳(N.Wiener)智力早熟,11岁就上了大学.他曾在1935~1936年应邀来中国清华大学讲学. 一次,他参加某个重要会议,年轻的脸孔引人注目.于是有人询问他的年龄, ...
- mybatis 逆向工程使用姿势不对,把表清空了,心里慌的一比,于是写了个插件。
使用mybatis逆向工程的时候,delete方法的使用姿势不对,导致表被清空了,在生产上一刷新后发现表里没数据了,一股凉意从脚板心直冲天灵盖. 于是开发了一个拦截器,并写下这篇文章记录并分享. 这锅 ...
- 拉勾网 + selenium
目录 方式一 selenium 方式二普通方法 方式一 selenium from selenium import webdriver import time from selenium.webdri ...
- String Problem(模板)【最短路】
String Problem 题目链接(点击) Boy Valera likes strings. And even more he likes them, when they are identic ...
- 并发系列(一)——线程池源码(ThreadPoolExecutor类)简析
前言 本文主要是结合源码去线程池执行任务的过程,基于JDK 11,整个过程基本与JDK 8相同. 个人水平有限,文中若有表达有误的,欢迎大伙留言指出,谢谢了! 一.线程池简介 1.1 使用线程池的优点 ...
- IP组网实验(使用Cisco Packet Tracer路由器模拟软件)
最近计网课讲到了以太网,第二个计网实验就是IP组网实验.这个实验主要使用了netsim这个路由器模拟软件.怎奈mac上没有,于是用Cisco Packet Tracer进行了一次模拟(其实就是实验中的 ...