BZOJ 1635: [Usaco2007 Jan]Tallest Cow 最高的牛
题目
1635: [Usaco2007 Jan]Tallest Cow 最高的牛
Time Limit: 5 Sec Memory Limit: 64 MB
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
HINT
Source
题解
差分序列,其实就是计算每一个点对之后所有点的贡献。
代码
/*Author:WNJXYK*/
#include<cstdio>
#include<algorithm>
using namespace std; struct Input{
int x,y;
Input(){ }
Input(int a,int b){
x=a;y=b;
}
}; const int MaxQ=;
const int Maxn=;
Input inp[MaxQ+];
int height;
int delta[Maxn+];
int n,r,h;
int index; bool cmp(Input a,Input b){
if (a.x<b.x) return true;
if (a.x==b.x && a.y<b.y) return true;
return false;
} int main(){
scanf("%d%d%d%d",&n,&index,&h,&r);
for (int i=;i<=r;i++){
int x,y;
scanf("%d%d",&x,&y);
if (x>y){
int tmp=x;x=y;y=tmp;
}
inp[i]=Input(x,y);
}
sort(inp+,inp+r+,cmp);
for (int i=;i<=r;i++){
if (inp[i].x==inp[i-].x && inp[i].y==inp[i-].y) continue;
delta[inp[i].y]++;delta[inp[i].x+]--;
}
for (int i=;i<=n;i++){
height+=delta[i];
printf("%d\n",h+height);
}
return ;
}
BZOJ 1635: [Usaco2007 Jan]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 ...
- 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 , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...
随机推荐
- 处理date类型对象的方式
在jsp中通过key属性映射到编译后jsp页面的name属性,通过model中的 setxxxx()方法将jsp页面通过wdatepicker插件产生的string类型的数据转换为timestamp类 ...
- Arduino周边模块:LED部件
Arduino周边模块:LED部件 Arduino周边模块:LED部件 1. LED的使用 LED的原理: LED是会发光的二极管,它具有单向导电性.两端加上正向电压,即能将电能转化为光能. 正向电压 ...
- 勉強すべきURL
http://www.atmarkit.co.jp/ait/articles/1403/19/news034_2.html http://webdesignerwork.jp/web/responsi ...
- 刷爆github小绿点
转载请注明出处:https://ahangchen.gitbooks.io/windy-afternoon/content/kit/git/green_blush.html 工程地址,欢迎star!! ...
- 转:Http头介绍:Expires,Cache-Control,Last-Modified,ETag
Http头介绍:Expires,Cache-Control,Last-Modified,ETag 缓存分很多种:服务器缓存,第三方缓存,浏览器缓存等.其中浏览器缓存是代价最小的,因为浏览器缓存依赖的是 ...
- 魔兽世界---屠夫(Just a Hook)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- uva 301 Transportation 铁路公司的阳谋 纯dfs暴力
题目比较难理解. 给出铁路的容量和站点数,以及几笔订单,要求算出如何盈利最大. 咋一看想贪心,但无法确定是最优解啊. 于是用dfs做,就两种状况,选与不选,先开一个每个站点的当前人数数组,假设要选,然 ...
- XX秘籍
第一课 一个男人在他妻子洗完澡后准备进浴室洗澡.这时,门铃响了. 妻子迅速用浴巾裹住自己冲到门口. 当她打开门时,邻居鲍勃站在那儿. 在她开口前,鲍勃说,“你如果把浴巾拿掉,我给你800美元.” 想了 ...
- Ajax或JS动态添加的元素,Jquery效果不起作用
问题: 最近在做一个Ajax分页的功能,遇到一个问题 一开始jquery效果是可用的,但是,ajax执行一次之后,jquery效果就无效了. 解决办法: 可以添加live事件来解决 W3C关于live ...
- VIM中格式化json
在vim输入以下命令就可以格式化:%!python -m json.tool可以在~/.vimrc增加快捷键map <F4><Esc>:%!python -m json.too ...