hdu 1556 Color the ball
来源:互联网 发布:移动gprs是几g网络 编辑:程序博客网 时间:2024/05/22 14:48
点击打开hdu 1556
思路; 树状数组
分析:
1 简单的区间更新,单点查询问题
代码:
/************************************************ By: chenguolin * * Date: 2013-08-20 ** Address: http://blog.csdn.net/chenguolinblog ************************************************/#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;const int MAXN = 100010;int n;int treeNum[MAXN];int lowbit(int x){ return x&(-x);}int getSum(int x){ int sum = 0; while(x){ sum += treeNum[x]; x -= lowbit(x); } return sum;}void add(int x , int val){ while(x < MAXN){ treeNum[x] += val; x += lowbit(x); }}void solve(){ int x , y , m; memset(treeNum , 0 , sizeof(treeNum)); m = n; while(m--){ scanf("%d%d" , &x , &y); add(x , 1); add(y+1 , -1); } printf("%d" , getSum(1)); for(int i = 2 ; i <= n ; i++) printf(" %d" , getSum(i)); puts("");}int main(){ while(scanf("%d" , &n) && n) solve(); return 0;}
- hdu 1556 color the ball
- hdu 1556Color 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 1556 Color the ball
- HDU 1556 Color the ball
- HDU 1556 Color the ball
- HDU 1556 Color the ball
- 一个jquery拖拽效果的实例
- 【Lucene3.6.2入门系列】第11节_高亮
- 三叶草
- 0 - 9的100——1000次方
- 利用Redis存储Session值的类
- hdu 1556 Color the ball
- cookie与session机制
- Struts1之国际化(一)
- iphone使用技巧
- ios 自定义view
- c符号优先级表备份
- [IOS]UITableView分区+索引显示
- VMWare6.5下redhat5.4中文乱码问题解决
- 数据库事务并发带来的问题