HDOJ/HDU 1556 Color the ball(树状数组)
Problem Description
N个气球排成一排,从左到右依次编号为1,2,3….N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽”牌电动车从气球a开始到气球b依次给每个气球涂一次颜色。但是N次以后lele已经忘记了第I个气球已经涂过几次颜色了,你能帮他算出每个气球被涂过几次颜色吗?
Input
每个测试实例第一行为一个整数N,(N <= 100000).接下来的N行,每行包括2个整数a b(1 <= a <= b <= N)。
当N = 0,输入结束。
Output
每个测试实例输出一行,包括N个整数,第I个数代表第I个气球总共被涂色的次数。
Sample Input
3
1 1
2 2
3 3
3
1 1
1 2
1 3
0
Sample Output
1 1 1
3 2 1
看到好多人做这个题都是用的线段树~~经过长时间尝试~发现完全可以不用线段树~
直接来一个数组离散化~树状数组
和插段求点相比有点变化
但是其实是差不多的。
插线段的话就在线段左端点加1,在右端点后面减一。
这样求和得到的就是这个点的染色次数了。
import java.util.Scanner;/*** @author 陈浩翔* 2016-5-26*/
public class Main{public static void main(String[] args) {Scanner sc =new Scanner(System.in);while(sc.hasNext()){int n =sc.nextInt();if(n==0){return;}int num[] = new int[n+5];for(int i=0;i<n;i++){int a=sc.nextInt();int b=sc.nextInt();num[a]++;num[b+1]--;}int m=num[1];System.out.print(m);for(int i=2;i<=n;i++){m+=num[i];System.out.print(" "+m);}System.out.println();}}
}
转载于:https://www.cnblogs.com/webmen/p/5739156.html
HDOJ/HDU 1556 Color the ball(树状数组)相关推荐
- HDU1556 Color the ball(树状数组+抖机灵)
题目: Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 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(树状数组)
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 ...
- 解题报告:hdu 1556 Color the ball(区间修改,单点查询)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556 Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N ...
- HDU 1556 Color the ball
题解:基础的树状数组区间修改,单点查询. #include <cstdio> #include <cstring> int c[100005],a,b,n; int modif ...
- HDU 1556 Color the ball - from lanshui_Yang
Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动 ...
- hdu 5157(manacher+前缀和+树状数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5157 解题思路: 我们可以先用mancher算法对字符串进行处理,把以每个点为中心的回文串半径求出来, ...
- HDU 5517---Triple(二维树状数组)
题目链接 Problem Description Given the finite multi-set A of n pairs of integers, an another finite mult ...
最新文章
- Python os库的使用
- 各类木材强度_层状磷酸锆/ 聚磷酸铵复合阻燃剂对木材的阻燃抑烟性能研究
- Cordic算法——verilog实现
- 【微信小程序企业级开发教程】视图与渲染详解
- SpringBoot—分层结构
- 怎样理解阻塞非阻塞与同步异步的区别?
- angular input使用输入框filter格式化日期
- 6 使用soap客户端_网络协议 20 - RPC 协议(上)- 基于XML的SOAP协议
- C# Attribute(中)——Attribute本质论
- 免费获取Silverlight Stream Service Account
- 使用Three.js的材质
- 关于ajax跨域的问题
- linux 共享内存 信号量 同步
- qesat/java,QESatJava白盒测试工具
- 【Python】爬取xici和快代理的免费代理ip
- hiBurn下载-hitool烧写鸿蒙2.0系统到Hi3861V100-从哪里找到芯片列表文件更新芯片列表-HarmonyOS
- 【Appium实战】如何使用mumu模拟器模拟安卓手机
- Caffe Solver
- 使用 LinuxGSM 搭建饥荒联机服务器(带洞穴)
- 小程序如何开通流量主