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的区间值相加,就是最后 ...
随机推荐
- Pots--poj(bfs,输出路径)
http://poj.org/problem?id=3414 题意: 给你两个容量为a,b的杯子:有3个操作: 1:FILL(i):把第i个杯子从水库中装满: 2:DROP(i):把第i个杯子清空: ...
- FS Shell命令手册
1. FS Shell 1.1 简介 调用文件系统(FS)Shell命令应使用 bin/hadoop fs <args>的形式. 所有的的FS shell命令使用URI ...
- oracle( 0 )事务
一.并发引起的问题 脏读:能读取未提交的数据 不可重复读:T1事务读取数据后,T2事务执行更新操作,使T1无法再现前一次读取的结果.分三种情况: 1.值不同 2.少了记录 3.多了记录 幻象读(后两种 ...
- JAVA包装类介绍(一)(包装类、基本类型数据)
1. 包装类把基本类型数据转换为对象 1.1每个基本类型在java.lang包中都有一个相应的包装类 2.包装类有何作用 2.1 提供了一系列实用的方法 2.2集合不允许存放基本数据类型 ...
- 关于LUA中的随机数问题
也许很多人会奇怪为什么使用LUA的时候,第一个随机数总是固定,而且常常是最小的那个值,下面我就简要的说明一下吧,说得不好,还请谅解.我现在使用的4.0版本的LUA,看的代码是5.0的,呵呵 LUA4. ...
- python内置函数大全(分类)
python内置函数大全 python内建函数 最近一直在看python的document,打算在基础方面重点看一下python的keyword.Build-in Function.Build-in ...
- [LeetCode] 331. Verify Preorder Serialization of a Binary Tree_Medium tag: stack
One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, ...
- Pandas之Dropna滤除缺失数据
import pandas as pd import numpy as np from numpy import nan as NaN 一.处理Series对象 通过dropna()滤除缺失数据 fr ...
- Mysql查询一个表的所有字段名
select COLUMN_NAME from information_schema.`COLUMNS` -- 这行不变,照抄 where TABLE_SCHEMA = 'xerp' ...
- matlab 怎么建立结构体数组?
https://zhidao.baidu.com/question/537198107.html 怎么定义一个结构体数组,使数组的每个元素是一个结构体变量.像这样:a=(1,2)a(1)=struct ...