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 , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...
随机推荐
- [计算机网络-应用层] DNS:因特网的目录服务
我们知道有两种方式可以识别主机:通过主机名或者IP地址.人们喜欢便于记忆的主机名标识,而路由器则喜欢定长的.有着层次结构的IP地址.为了折中这些不同的偏好,我们需要一种能进行主机名到IP地址转换的目录 ...
- 【.Net】浅谈C#中的值类型和引用类型
在C#中,值类型和引用类型是相当重要的两个概念,必须在设计类型的时候就决定类型实例的行为.如果在编写代码时不能理解引用类型和值类型的区别,那么将会给代码带来不必要的异常.很多人就是因为没有弄清楚这两个 ...
- 【Python】python更新数据库脚本两种方法
最近项目的两次版本迭代中,根据业务需求的变化,需要对数据库进行更新,两次分别使用了不同的方式进行更新. 第一种:使用python的MySQLdb模块利用原生的sql语句进行更新 1 import ...
- BZOJ 1297 迷路(矩阵快速幂)
很容易想到记忆化搜索的算法. 令dp[n][T]为到达n点时时间为T的路径条数.则dp[n][T]=sigma(dp[i][T-G[i][n]]); 但是空间复杂度为O(n*T),时间复杂度O(n*n ...
- CentOS 文件隐藏属性
1.chattr用于配置文件的隐藏属性 语法: chattr [-RVf] [-+=aAcCdDeijsStTu] [-v version] files... 选项与参数: +:增加某个特殊参数,其他 ...
- POJ1375:Intervals——题解
http://poj.org/problem?id=1375 题目大意:有一盏灯,求每段被圆的投影所覆盖的区间. —————————————————————— 神题,卡精度,尝试用各种方法绕过精度都不 ...
- 斜率优化第一题! HDU3507 | 单调队列优化DP
放一手原题 题解: 第一次写(抄)斜率优化,心里还是有点小激动的.讲一下怎么实现的! 首先我们可以考虑一个朴素的dp:DP[i]表示前i个数字的最少花费,显然我们有一个转移方程 DP[i]=min{D ...
- BZOJ3542 DZY Loves March 【map + 线段树】
题目链接 BZOJ3542 题解 线段树裸题,,对每一行每一列开线段树 由于坐标很大,用\(map\)维护根下标 化一下式子,只用维护区间和,区间平方和,区间存在的个数 #include<alg ...
- bzoj Usaco补完计划(优先级 Gold>Silver>资格赛)
听说KPM初二暑假就补完了啊%%% 先刷Gold再刷Silver(因为目测没那么多时间刷Silver,方便以后TJ2333(雾 按AC数降序刷 ---------------------------- ...
- BAT-Java必考面试题集
2018最新<BAT Java必考面试题集> 1.面向对象的特征有哪些方面? 答:面向对象的特征主要有以下几个方面: 1)抽象:抽象是将一类对象的共同特征总结出来构造类的过程,包括数据抽象 ...