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 , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...
随机推荐
- Linux学习之修改主机名
1.临时修改主机名 显示主机名: oracle@localhost:~$ hostname localhost 修改主机名: oracle@localhost:~$ sudo hostname orc ...
- php Mysql 和Mysqli数据库函数整合
PHP Mysql和Mysqli数据库函数整合 服务器如果支持mysqli函数将优先mysqli函数进行数据库操作 否则将调用mysql函数进行数据库操作 用法SQL::connect(host,us ...
- zend framework安装中出现的问题与总结
1.按照官方的教程来做http://framework.zend.com/manual/current/en/user-guide/skeleton-application.html 但其中有些步骤没 ...
- 基于Socket的UDP和TCP编程介绍
一.概述 TCP(传输控制协议)和UDP(用户数据报协议是网络体系结构TCP/IP模型中传输层一层中的两个不同的通信协议. TCP:传输控制协议,一种面向连接的协议,给用户进程提供可靠的全双工的字节流 ...
- NOI2011 Day1
NOI2011 Day1 兔农 题目描述:\(fib[1]=fib[2]=1, fib[i]=fib[i-2]+fib[i-1] (i\geq 3)\),若\(fib[i] \equiv 1(mod ...
- springMVC+spring+mybatis整合过程中遇到的问题
今天在配置SSM整合的过程中遇到了几个错误,折腾了好久,具体如下 1.java.lang.IllegalArgumentException: Mapped Statements collection ...
- Day3_字符串操作与正则表达式
本节课的主要内容有:字符串的格式化.连接与分割.比较.匹配和替换.使用正则表达式 字符串的格式化: 去除空格:trim() 使用html格式化:nl2br() 替换‘\n’为‘<br /> ...
- error while loading shared libraries: libevent-1.x.so.1
安装完memcache后启动报错(error while loading shared libraries: libevent-1.x.so.1) 这是由于64位linux会去/usr/lib64目录 ...
- JS判断是否安装flash player及当前版本
function flashChecker() { var hasFlash = 0; //是否安装了flash var flashVersion = 0; //flash版本 if(document ...
- Dyanmics CRM您无法登陆系统。原因可能是您的用户记录或所属的业务部门在Microoft Dynamics CRM中已被禁用
当在操作CRM时,做不论什么的写操作包含创建数据.更新数据.都会提示以下截图中的错误:"您无法登陆系统.原因可能是您的用户记录或所属的业务部门在Microoft Dynamics CRM中已 ...