hdu 1556 Color the ball
来源:互联网 发布:同济启明星软件 编辑:程序博客网 时间:2024/05/18 22:53
看了这篇文章复习了下数状数组:http://blog.csdn.net/clx55555/article/details/52261538
这个题的思路是在起始位置加1,结束位置的下一个减1,这样从1~n的和就是n被染色的次数。
数状数组的思想挺有意思的,不得不佩服想出这个思想的人
#include <stdio.h>#include <iostream>#include <string.h>#include <algorithm>using namespace std;const int maxn=100009;int n;int a[maxn];int low_bit(int x){ return x&(-x);}void add(int x,int val){ for(int i=x; i<=n; i+=low_bit(i)) a[i]+=val;}int sum(int x){ int ans=0; for(int i=x; i>=1; i-=low_bit(i)) ans+=a[i]; return ans;}int main(){ while(~scanf("%d",&n)&&n) { memset(a,0,sizeof(a)); int x,y; for(int i=1; i<=n; i++) { scanf("%d%d",&x,&y); add(x,1); add(y+1,-1); } for(int i=1; i<n; i++) printf("%d ",sum(i)); printf("%d\n",sum(n)); } return 0;}
阅读全文
0 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
- #HDU 2845 Beans 最大不连续子列和
- win环境 开启pgsql 扩展
- PHP与MySQL数据库连接
- 小白的Python之路
- ios 3Dtouch 照片预览
- hdu 1556 Color the ball
- javascript显示年月日时间代码
- POI导出Excel三
- flv
- EventBus之简单用法
- 你所看到较轻松的Dagger2(使用扩展)
- Android中Handler、Looper、Message、MessageQueue详解
- 【spring】事务管理之声明式事务
- Android对接支付宝移动支付始终无法成功调用H5PayActivity