HDU 1556 Color the ball (只做区间更新)
来源:互联网 发布:开票软件为什么打不开 编辑:程序博客网 时间:2024/06/05 14:41
思路:本题只做区间更新,而不查询。方法很多,线段树是大才小用,代码长不说,在线地维护区间会TLE。故离线之。
线段树的做法:
<span style="font-size:14px;">#include <bits/stdc++.h>using namespace std;const int MAXN=100000+1000;int st,en,tree[3*MAXN],ans[MAXN],ppp;void update(int l,int r,int rt){ if(st<=l&&r<=en){ tree[rt]++; return ; } int mid=(l+r)/2; if(st<=mid) update(l,mid,rt*2); if(mid<en) update(mid+1,r,rt*2+1); return ;}void push_down(int rt){ tree[rt*2]+=tree[rt]; tree[rt*2+1]+=tree[rt];}void dfs(int l,int r,int rt){ if(l==r){ ans[++ppp]=tree[rt];return ; } push_down(rt); int mid=(l+r)/2; dfs(l,mid,rt*2); dfs(mid+1,r,rt*2+1); return ;}int main(){ int n; while(~scanf("%d",&n),n){ memset(tree,0,sizeof(tree)); for(int i=0;i<n;i++){ scanf("%d%d",&st,&en); update(1,n,1); } ppp=-1; dfs(1,n,1); printf("%d",ans[0]); for(int i=1;i<n;i++) printf(" %d",ans[i]); printf("\n"); }}</span><span style="font-size:24px;"></span>
离线扫描线的做法:
<span style="font-size:14px;">#include <bits/stdc++.h>using namespace std;const int MAXN=100000+1000;int st,en,ans[MAXN];int main(){ int n; while(cin>>n&&n){ memset(ans,0,sizeof(ans)); for(int i=0;i<n;i++){ scanf("%d%d",&st,&en); ans[st]++; ans[en+1]--; } printf("%d",ans[1]); for(int i=2;i<=n;i++){ ans[i]+=ans[i-1]; printf(" %d",ans[i]); } cout<<endl; }}</span>
0 0
- HDU 1556 Color the ball (只做区间更新)
- 区间更新问题总结(hdu 1556 Color the ball)
- HDU 1556 Color the ball(线段树区间更新)
- HDU 1556-Color the ball(线段树区间更新)
- hdu 1556 Color the ball(区间更新,查询点)
- HDU 1556 Color the ball [区间更新+单点查询]
- HDU 1556 Color the ball 线段树更新区间查点
- HDU 1556 Color the ball【树状数组+区间更新】
- HDU - 1556 Color the ball (线段树 + 区间更新)
- HDU 1556 Color the ball 线段树 区间更新
- HDU 1556 Color the ball(树状数组区间更新)
- HDU 1556 Color the ball(线段树区间更新)
- HDU 1556 Color the ball 树状数组-区间更新-模板
- hdu 1566 Color the ball(线段树区间更新)
- HDU 1556 Color the ball(线段树区间更新区间查询模板)
- Hdu oj 1556 Color the ball(树状数组区间更新转单点更新)
- hdu 1556 Color the ball(线段树 区间更新单点查询)
- HDU 1556 Color the ball(线段树的区间更新【注释】)
- 1.ssm框架springmvc拦截"/"后资源文件找不到问题
- Android Studio教程
- 整理的Java资源大全
- Mac osx 10.10 苹果机上用DD制作Ubuntu的USB启动盘
- spring aop 简单实例
- HDU 1556 Color the ball (只做区间更新)
- 微信支付
- C语言中双感叹号(!!)的含义
- weex服务项目搭建
- 源码编译安装 Mysql5.5
- HorizontalListView自定义
- eclipse动态调试smali
- Qt中定时器使用的两种方法
- 利用阿里大于实现发送短信(JAVA版)