bzoj 1635: [Usaco2007 Jan]Tallest Cow 最高的牛——差分
Description
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.
有n(1 <= n <= 10000)头牛从1到n线性排列,每头牛的高度为h[i](1 <= i <= n),现在告诉你这里面的牛的最大高度为maxH,而且有r组关系,每组关系输入两个数字,假设为a和b,表示第a头牛能看到第b头牛,能看到的条件是a, b之间的其它牛的高度都严格小于min(h[a], h[b]),而h[b] >= h[a]
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
1 3
5 3
4 3
3 7
9 8
INPUT DETAILS:
There are 9 cows, and the 3rd is the tallest with height 5.
Sample Output
4
5
3
4
4
5
5
5
#include<cstdio>
#include<cstring>
#include<algorithm>
using std::swap;
const int M=2e4+;
int read(){
int ans=,f=,c=getchar();
while(c<''||c>''){if(c=='-') f=-; c=getchar();}
while(c>=''&&c<=''){ans=ans*+(c-''); c=getchar();}
return ans*f;
}
int n,h,m,now;
int f[M],x,y;
struct pos{int x,y;}q[M];
bool cmp(pos a,pos b){return a.x!=b.x?a.x<b.x:a.y<b.y;}
int main(){
n=read(); read(); h=read(); m=read();
for(int i=;i<=m;i++){
x=read(); y=read();
if(x>y) swap(x,y);
q[i].x=x; q[i].y=y;
}std::sort(q+,q++m,cmp);
for(int i=;i<=m;i++){
if(q[i].x==q[i-].x&&q[i].y==q[i-].y) continue;
f[q[i].x+]--; f[q[i].y]++;
}
for(int i=;i<=n;i++){
now+=f[i];
printf("%d\n",h+now);
}
return ;
}
bzoj 1635: [Usaco2007 Jan]Tallest Cow 最高的牛——差分的更多相关文章
- BZOJ 1635: [Usaco2007 Jan]Tallest Cow 最高的牛
题目 1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec Memory Limit: 64 MB Description FJ's N ( ...
- bzoj 1635: [Usaco2007 Jan]Tallest Cow 最高的牛【差分】
s[i]为差分后的"i这头牛前有几头比它高",计算答案的时候加成前缀和,假设第一头最高减一下即可 用map记录一下被加过的区间,避免重复 #include<iostream& ...
- 1635: [Usaco2007 Jan]Tallest Cow 最高的牛
1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 383 Solved: 211 ...
- 【BZOJ】1635: [Usaco2007 Jan]Tallest Cow 最高的牛(差分序列)
http://www.lydsy.com/JudgeOnline/problem.php?id=1635 差分序列是个好东西啊....很多地方都用了啊,,, 线性的进行区间操作orz 有题可知 h[a ...
- 【BZOJ】1635: [Usaco2007 Jan]Tallest Cow 最高的牛
[题意]n头牛,其中最高h.给定r组关系a和b,要求满足h[b]>=h[a]且a.b之间都小于min(h[a],h[b]),求第i头牛可能的最高高度. [算法]差分 [题解]容易发现r组关系只能 ...
- BZOJ1635: [Usaco2007 Jan]Tallest Cow 最高的牛
1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 346 Solved: 184 ...
- bzoj 1701 [Usaco2007 Jan]Cow School牛学校
[Usaco2007 Jan]Cow School牛学校 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 175 Solved: 83[Submit][S ...
- bzoj 1636: [Usaco2007 Jan]Balanced Lineup -- 线段树
1636: [Usaco2007 Jan]Balanced Lineup Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 772 Solved: 560线 ...
- BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花( 贪心 )
考虑相邻的两头奶牛 a , b , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...
随机推荐
- [贪心经典算法]Kruskal算法
Kruskal算法的高效实现需要一种称作并查集的结构.我们在这里不介绍并查集,只介绍Kruskal算法的基本思想和证明,实现留在以后讨论. Kruskal算法的过程: (1) 将全部边按照权值由小到大 ...
- IPReversePathFilter
nstat TcpExtIPReversePathFilter for i in /proc/sys/net/ipv4/conf/*/rp_filter ; do > echo 0 > $ ...
- pycharm开启代码智能提示和报错提示
天呐,经历了一大波周折,终于把提示给弄好了,加入没有提示的话,pycharm就是一个空格了,没有什么作用,对我来说,真的是很困难的事情,所以无论如何都要去把这个智能提示给搞好了. 先讲讲我的经历吧.我 ...
- /proc/meminfo中meminfo的计算方法
/proc/meminfo里的可使用内存的计算没有那么简单,并不是简单的free和page cache的加和 free + pagecache 以此为基准 但是需要减去一些内存:首先要减去系统预留的内 ...
- BZOJ 1191 超级英雄(二分图匹配)
把题目作为s集,锦囊作为t集.把每个题目和它可以用的锦囊连边,这样就构成了一个二分图,求出这个二分图最大匹配. 但是这个最大匹配有限制条件,就是对于每个可能的匹配集,如果s集的i点有匹配,那么i-1点 ...
- C# 面向对象——多态
多态分三种:1.虚方法 2.抽象类 3.接口 1.虚方法1.将父类的方法标记为虚方法 ,使用关键字 virtual,这个函数可以被子类重新写一个遍. 如: class Program { static ...
- 【题解】51nod 1686第K大区间
成功的秘诀,在于克服自己看题解的冲动……[笑哭].自己A掉这题还是灰常开心的~ 以及爱死 two - pointer ! two - pointer 大法是真的好哇……这个题目有上一题的经验:求第\( ...
- BZOJ1297:[SCOI2009]迷路——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1297 windy在有向图中迷路了. 该有向图有 N 个节点,windy从节点 0 出发,他必须恰好在 ...
- POJ.3624 Charm Bracelet(DP 01背包)
POJ.3624 Charm Bracelet(DP 01背包) 题意分析 裸01背包 代码总览 #include <iostream> #include <cstdio> # ...
- python3.5安装pycrypto
在python中使用AES加密是一种有效的加密方式,如果你研究过微信公众号api就会发现,它也用的是这个加密的.在写代码的时候,要安装crypto模块,在linux或者mac上都好说,但是在windo ...