poj 3263 Tallest Cow(线段树)
来源:互联网 发布:如何做好淘宝客服 编辑:程序博客网 时间:2024/05/16 15:32
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.
Input
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
Sample Input
9 3 5 51 35 34 33 79 8
Sample Output
545344555
Source
题意:给出牛的可能最高身高,然后输入m组数据 a b,代表a,b可以相望,最后求所有牛的可能最高身高输出
注意问题:1>可能有重边
2> a,b可以相望就是要降低a+1到b-1之间的牛的身高
详情看代码:
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#define L(x) (x<<1)#define R(x) (x<<1|1)#define MID(x,y) ((x+y)>>1)using namespace std;#define INF 0x3f3f3f3f#define N 1000005int n,i,h,m;int lle[N],rri[N],k;struct stud{int le,ri;int va;}f[N];void pushdown(int pos){ if(f[pos].va==0) return ; f[L(pos)].va+=f[pos].va; f[R(pos)].va+=f[pos].va; f[pos].va=0;}void build(int pos,int le,int ri){f[pos].le=le;f[pos].ri=ri;f[pos].va=0;if(le==ri) return;int mid=MID(le,ri);build(L(pos),le,mid);build(R(pos),mid+1,ri);}void update(int pos,int le,int ri){if(f[pos].le==le&&f[pos].ri==ri){f[pos].va++;return ;} pushdown(pos); int mid=MID(f[pos].le,f[pos].ri); if(mid>=ri)update(L(pos),le,ri);elseif(mid<le)update(R(pos),le,ri);else{update(L(pos),le,mid);update(R(pos),mid+1,ri);}}int query(int pos,int le){if(f[pos].le==le&&f[pos].ri==le){return h-f[pos].va;} pushdown(pos); int mid=MID(f[pos].le,f[pos].ri); if(mid>=le)return query(L(pos),le);elsereturn query(R(pos),le);}int main(){int i,j;while(~scanf("%d%d%d%d",&n,&i,&h,&m)){build(1,1,n);k=0;lle[0]=rri[0]=0;int le,ri;while(m--){scanf("%d%d",&le,&ri);if(le>ri) {i=le; le=ri;ri=i;}if(le+1==ri) continue;for(i=0;i<k;i++)if(lle[i]==le&&rri[i]==ri){i=-1;break;} if(i==-1) continue; lle[k]=le; rri[k++]=ri; update(1,le+1,ri-1);} for(i=1;i<=n;i++){printf("%d\n",query(1,i));}} return 0;}
- POJ 3263 Tallest Cow(线段树)
- poj 3263 Tallest Cow(线段树)
- poj 3263 Tallest Cow
- POJ 3263 Tallest Cow
- Tallest Cow POJ
- 【poj】2828 Buy Tickets、2182 Lost Cow(线段树-单点更新)
- poj 3167 Cow Patterns (kmp + 线段树/树状数组)
- bzoj1635: [Usaco2007Jan]Tallest Cow 最高的牛
- poj 1985 Cow Marathon(树直径)
- Bzoj 4422: [Cerc2015]Cow Confinement(线段树+扫描线)
- [BZOJ4422][Cerc2015]Cow Confinement(扫描线+线段树)
- BZOJ 1635: [Usaco2007 Jan]Tallest Cow 最高的牛
- bzoj1635 [Usaco2007 Jan]Tallest Cow 最高的牛
- bzoj 1635: [Usaco2007 Jan]Tallest Cow 最高的牛
- 【bzoj 1635】: [Usaco2007 Jan]Tallest Cow 最高的牛
- 1635: [Usaco2007 Jan]Tallest Cow 最高的牛
- bzoj1635: [Usaco2007 Jan]Tallest Cow 最高的牛
- BZOJ1635 [Usaco2007 Jan]Tallest Cow 最高的牛
- 解决eclipse中logcat不显示log的问题
- SDUT 1225-编辑距离(串型dp)
- Oracle起步学习(七)--组函数
- 在SurfaceView中绘制文本时 无法自动换行问题的解决办法
- Code Blocks IDE
- poj 3263 Tallest Cow(线段树)
- HTTP 错误 500.19 - Internal Server Error 无法访问请求的页面,因为该页的相关配置数据无效。
- hdu 1789 Doing Homework again
- ios(ipad,iphone)屏幕旋转检测通用方法
- UVA 147 Dollars (完全背包)
- Restful 和 Jersey介绍(Web Service )
- 【Processing入门】Processing第三章:绘图下
- 软件工程总结——下
- 队伍最前面的三个年轻人动作如一的向前迈进一步。