hdu1556 Color the ball
题目链接: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相关推荐
- HDU1556 Color the ball【差分数组+线段树】
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU1556 Color the ball(树状数组+抖机灵)
题目: Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- nyoj-228(士兵杀敌五) hdu-1556 Color the ball
巧用数组,貌似很牛逼,还需多多体会才能感觉其中的高深 nyoj-228 #include<stdio.h> #include<string.h> #include<alg ...
- hdu1556(Color the ball )
N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一 ...
- hdu 1556 Color the ball
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- Color the ball
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu 1556:Color the ball(第二类树状数组 —— 区间更新,点求和)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 1556 Color the ball (数状数组)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 杭电1556 Color the ball
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
最新文章
- 使用微波炉的十大忌讳
- Boost:bind绑定的转发测试
- Spring5的Web 组件
- RabbitMQ消息确认以及return机制
- 【戴嘉乐】(进阶)基于IPFS和Ngrok构建自维护资源网关
- [Java] 蓝桥杯ADV-102 算法提高 单词个数统计
- CSS高级技巧【学习笔记】
- C++: 对字符串转换字符集(编码)
- nginx启动报错 :Failed to start The nginx HTTP and reverse prox...er.
- Stata:投资效率
- 如何使用git上传项目至GitHub repository
- 猿辅导python大纲_数据解读独角兽企业“猿辅导”(第一部分)
- vscode修改代码颜色
- 黑盒测试用例设计方法-正交试验
- c语言实现10个数由小到大排序(插入排序法)
- 项目启动tomcat失败的几种可能原因和解决方法
- n个不同元素进栈,求出栈元素不同排列的个数
- vue-seamless-scroll 点击click失效
- 解决 Starting MySQL ERROR The server quit without updating PID file
- Web前端是做什么的?就业前景好吗?