【差分】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 ...
随机推荐
- Linux内存管理—详细讲解
摘要:本章首先以应用程序开发者的角度审视Linux的进程内存管理,在此基础上逐步深入到内核中讨论系统物理内存管理和内核内存的使用方法.力求从外到内.水到渠成地引导网友分析Linux的内存管理与使用.在 ...
- 快速搭建基于Spring Boot + Spring Security 环境
个人博客网:https://wushaopei.github.io/ (你想要这里多有) 1.Spring Security 权限管理框架介绍 简介: Spring Security 提供了基于 ...
- Java实现 LeetCode 443 压缩字符串
443. 压缩字符串 给定一组字符,使用原地算法将其压缩. 压缩后的长度必须始终小于或等于原数组长度. 数组的每个元素应该是长度为1 的字符(不是 int 整数类型). 在完成原地修改输入数组后,返回 ...
- Java中Iterator类的详细介绍
迭代器模式:就是提供一种方法对一个容器对象中的各个元素进行访问,而又不暴露该对象容器的内部细节. 概述 Java集合框架的集合类,我们有时候称之为容器.容器的种类有很多种,比如ArrayList.Li ...
- Android中如何使用单选对话框
给Button设置OnClick事件设置 int id=0; final String [] s={"单选A","单选B","单选C",&q ...
- Java实现第十届蓝桥杯最大降雨量
试题 E: 最大降雨量 本题总分:15 分 [问题描述] 由于沙之国长年干旱,法师小明准备施展自己的一个神秘法术来求雨. 这个法术需要用到他手中的 49 张法术符,上面分别写着 1 至 49 这 49 ...
- java实现第四届蓝桥杯空白格式化
空白格式化 本次大赛采用了全自动机器测评系统. 如果你的答案与标准答案相差了一个空格,很可能无法得分,所以要加倍谨慎! 但也不必过于惊慌.因为在有些情况下,测评系统会把你的答案进行"空白格式 ...
- 去摆摊吧,落魄的Java程序员
真的,我也打算去摆摊,宣传语我都想好了.沉默王二,一枚有颜值却靠才华苟且的程序员,<Web 全栈开发进阶之路>作者,CSDN 明星博主,周排名第 4,总排名 40,这数据在众多互联网大咖面 ...
- 卷积生成对抗网络(DCGAN)---生成手写数字
深度卷积生成对抗网络(DCGAN) ---- 生成 MNIST 手写图片 1.基本原理 生成对抗网络(GAN)由2个重要的部分构成: 生成器(Generator):通过机器生成数据(大部分情况下是图像 ...
- STL中常用算法
一.排序 sort sort(first_pointer,first_pointer+n,cmp) 默认为升序 若要使用降序,自行写cmp 函数 bool cmp(int a,int b){ retu ...