题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556

思路:

我自己是用线段树做的

后来看了kuangbin的博客,发现用树状数组更简单,而且很妙,就自己也敲了一下

对于会树状数组的同学来说理解代码应该很简单,直接贴代码了啊

代码:

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<string>
 4 #include<iostream>
 5 #include<cstring>
 6 using namespace std;
 7
 8 const int MAXN=100010;
 9 int c[MAXN];
10 int n;
11
12 int lowbit(int x)
13 {
14     return x&(-x);
15 }
16 void add(int i,int val)
17 {
18     while(i<=n)
19     {
20         c[i]+=val;
21         i+=lowbit(i);
22     }
23 }
24 int sum(int i)
25 {
26     int s=0;
27     while(i>0)
28     {
29         s+=c[i];
30         i-=lowbit(i);
31     }
32     return s;
33 }
34 int main()
35 {
36     int a,b;
37     while(scanf("%d",&n),n)
38     {
39         memset(c,0,sizeof(c));
40         for(int i=0;i<n;i++)
41         {
42             scanf("%d%d",&a,&b);
43             add(a,1);
44             add(b+1,-1);
45         }
46         for(int i=1;i<n;i++)
47          cout<<sum(i)<<" ";
48          cout<<sum(n)<<endl;
49     }
50     return 0;
51 }

转载于:https://www.cnblogs.com/xiaozhuyang/p/hdu1556_1.html

hdu1556 Color the ball相关推荐

  1. HDU1556 Color the ball【差分数组+线段树】

    Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...

  2. HDU1556 Color the ball(树状数组+抖机灵)

    题目: Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  3. nyoj-228(士兵杀敌五) hdu-1556 Color the ball

    巧用数组,貌似很牛逼,还需多多体会才能感觉其中的高深 nyoj-228 #include<stdio.h> #include<string.h> #include<alg ...

  4. hdu1556(Color the ball )

    N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一 ...

  5. hdu 1556 Color the ball

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  6. Color the ball

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  7. hdu 1556:Color the ball(第二类树状数组 —— 区间更新,点求和)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  8. HDU 1556 Color the ball (数状数组)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  9. 杭电1556 Color the ball

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

最新文章

  1. 使用微波炉的十大忌讳
  2. Boost:bind绑定的转发测试
  3. Spring5的Web 组件
  4. RabbitMQ消息确认以及return机制
  5. 【戴嘉乐】(进阶)基于IPFS和Ngrok构建自维护资源网关
  6. [Java] 蓝桥杯ADV-102 算法提高 单词个数统计
  7. CSS高级技巧【学习笔记】
  8. C++: 对字符串转换字符集(编码)
  9. nginx启动报错 :Failed to start The nginx HTTP and reverse prox...er.
  10. Stata:投资效率
  11. 如何使用git上传项目至GitHub repository
  12. 猿辅导python大纲_数据解读独角兽企业“猿辅导”(第一部分)
  13. vscode修改代码颜色
  14. 黑盒测试用例设计方法-正交试验
  15. c语言实现10个数由小到大排序(插入排序法)
  16. 项目启动tomcat失败的几种可能原因和解决方法
  17. n个不同元素进栈,求出栈元素不同排列的个数
  18. vue-seamless-scroll 点击click失效
  19. 解决 Starting MySQL ERROR The server quit without updating PID file
  20. Web前端是做什么的?就业前景好吗?

热门文章

  1. 2、网络编程之基于UDP示例
  2. Asp.Net MVC 体验 2 持久层的构建
  3. DevExpress小结(简略)
  4. 计算机网络学习笔记(4. Internet结构)
  5. MySQL学习(一)—初识MySQL
  6. 你小时候家里最穷的时候有多穷?
  7. 如何安装TrueNAS
  8. 我有一张1996年版一元钱,值多少钱?
  9. 一个5g基站的覆盖范围有多大,有没有4g的大?
  10. 盘点《令人心动的offer》中让人敲黑板的重点