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 , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...
随机推荐
- Apache配置参数
Apache的配置文件 配置文件所在目录:/etc/httpd/conf/主配置文件:httpd.conf旧版本中的配置文件:资源配置文件:srm.conf访问许可权配置文件:access.conf ...
- 密码学——网间数据加密传输全流程(SSL加密原理)
0.导言 昨天写了一篇关于<秘钥与公钥>的文章,写的比较简单好理解,有点儿像过家家,如果详细探究起来会有不少出入,今天就来详细的说明一下数据加密的原理和过程.这个原理就是大名鼎鼎SSL的加 ...
- Orchard 源码探索(Localization)之国际化与本地化
本地化与国际化 基本上相关代码都在在Orchard.Framework.Localization中. T("english")是如何调用到WebViewPage.cs中的Local ...
- OSG坐标系统
1.世界坐标 世界坐标系描述的是整个场景中所有的对象,可以理解为绝对坐标系,所有对象的位置都是绝对坐标.从整体上考虑,它为所有对象的位置提供一个绝对的参考标准,从而避免了物体之间由于独 ...
- 谈谈文件增量同步算法:RSYNC和CDC
谈谈文件增量同步算法:RSYNC和CDC 分类: 数据同步 增量备份 版权声明:本文为博主原创文章,未经博主允许不得转载. 最近在研究文件的增量同步问题,着重研究了文件差异编码部分,因为这个其实是文件 ...
- CSS---input标签注意
总结一下,在给input标签写CSS时需要注意的有以下几点: 一.不要给属性为text的input标签设置高度,这样无法让IE浏览器下输入框中的文字垂直居中显示.尽管你后来想要通过设置padding属 ...
- Oracle EBS-SQL (INV-2):库存会计期间.sql
SELECT STATUS, PERIOD_NAME, PERIOD_NUMBER, PERIOD_YEAR, START_DATE, END_DATE, CLOSE_DATE, REC_TYPE, ...
- Nand ECC校验和纠错原理及2.6.27内核ECC代码分析
ECC的全称是Error Checking and Correction,是一种用于Nand的差错检测和修正算法.如果操作时序和电路稳定性不存在问题的话,NAND Flash出错的时候一般不会造成整个 ...
- Ultra-QuickSort(归并排序)
Ultra-QuickSort Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 49267 Accepted: 18035 ...
- 【和我一起学习Unity3D】Unity3D的坐标控制
坐标这个东西,在Unity3D里面是分为几个类的,各自是Vector2,Vector3.Vector4:含义各自是:二维坐标系,三维坐标系,四维坐标系.一般做游戏呢,用到的最多的就是Vector3了. ...