HDU1556 Color the ball(差分数组)题解
Color the ball
当N = 0,输入结束。
1 1
2 2
3 3
3
1 1
1 2
1 3
0
3 2 1
思路:
昨天刚学的,没时间写,今天写出来,感觉很简单方便,可以看这个连接,讲的比较详细
Code:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<queue>
#include<cmath>
#include<map>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=100005;
int b[N];
int main(){
int n,l,r;
int sum;
while(~scanf("%d",&n) && n){
memset(b,0,sizeof(b));
for(int j=0;j<n;j++){
scanf("%d%d",&l,&r);
b[l]++;
b[r+1]--;
}
sum=0;
for(int i=1;i<=n;i++){
if(i!=1) printf(" ");
sum+=b[i];
printf("%d",sum);
}
printf("\n");
}
return 0;
}
HDU1556 Color the ball(差分数组)题解的更多相关文章
- Color the ball(差分数组)
N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色.但 ...
- HDU1556 Color the ball & 牛客 contest 135-I 区间 [差分标记]
一.差分标记介绍 差分标记用来解决针对区间(修改-查询)的问题,复杂度比线段树要更低.推荐这个博客. 例如,给数组中处于某个区间的数进行加减操作,然后查询某个位置上数的变化值. 二.HDU1556 C ...
- HDU1556:Color the ball(简单的线段树区域更新)
http://acm.hdu.edu.cn/showproblem.php?pid=1556 Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定 ...
- hdu-1556 Color the ball---树状数组+区间修改单点查询
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1556 题目大意: Problem Description N个气球排成一排,从左到右依次编号为1,2 ...
- HDU1556 Color the ball [线段树模板]
题意:区间修改序列值,最后输出. //hdu1166 #include<iostream> #include<cstdio> #include<cstring> # ...
- hdu1556 Color the ball
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> ...
- HDU 1556 Color the Ball 线段树 题解
本题使用线段树自然能够,由于区间的问题. 这里比較难想的就是: 1 最后更新须要查询全部叶子节点的值,故此须要使用O(nlgn)时间效率更新全部点. 2 截取区间不能有半点差错.否则答案错误. 这两点 ...
- hdu1556 Color the ball 简单线段树
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556 简单的线段树的应用 直接贴代码了: 代码: #include<iostream> # ...
- hdu1556 Color the ball 线段树区间染色问题
都是老套路了,如果n=5,要把区间[1,4]染色,可以递归去染区间[1,3]和区间[4,4],如果区间相等就自加,不相等继续递归寻找对应区间. 打印结果时,把所有到达叶节点包含i的区间值相加,就是最后 ...
随机推荐
- 【python+opencv】直线检测+圆检测
Python+OpenCV图像处理—— 直线检测 直线检测理论知识: 1.霍夫变换(Hough Transform) 霍夫变换是图像处理中从图像中识别几何形状的基本方法之一,应用很广泛,也有很多改进 ...
- 【python-opencv】20-图像金字塔
知识点介绍 图像金字塔原理: 高斯金字塔 拉普拉斯金字塔: 代码层面知识点: cv2.PyrDown:降采样 cv2.PyrUp:升采样 高斯金字塔与拉普拉斯金字塔 图像金字塔是图像中多尺度表达的 ...
- oracle(三) SQL语句
1.聚集函数遇到空值时,除count(*)外,都会跳过空值. 2.group by 细化聚集函数的作用对象 3.group by有个原则,就是select后面出面的列,除聚集函数外必须出现在group ...
- android动态设置边框颜色
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http: ...
- 011-jdk1.8版本新特性三-Date API
1.7.Date API Java 8 在包java.time下包含了一组全新的时间日期API.新的日期API和开源的Joda-Time库差不多,但又不完全一样,下面的例子展示了这组新API里最重要的 ...
- 使用浏览器,调试js代码
1:创建html网页和js文件 <!doctype html> <html> <head> <meta charset="utf-8"&g ...
- Spark Storage(一) 集群下的区块管理
Storage模块 在Spark中提及最多的是RDD,而RDD所交互的数据是通过Storage来实现和管理 Storage模块整体架构 1. 存储层 在Spark里,单节点的Storage的管理是通过 ...
- iOS 网易彩票-6设置模块三(常用小功能)
该篇文章中,用到很多iOS开发过程中常用的小功能,当前只是将这些功能集成到网易彩票的设置中.iOS-常用小功能介绍,请参考我的另一篇文章: iOS 常用小功能 总结:http://www.cnblog ...
- winform dataGridView DataGridViewComboBoxColumn 下拉框事件代码
有一个dataGridView ,有一列是DataGridViewComboBoxColumn .我用动态绑定,在绑定数据的时候.我们也给这一列绑定数据 在dataGridView的RowsAdded ...
- html08
1.JQuery 是一个js框架一堆的 js文件 -形成 > 包 - 形成> 工具 - 形成> ->库 -> 框架 是一个轻量级的库 封装了js原生里js css dom ...