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的区间值相加,就是最后 ...
随机推荐
- Linux连接字符串
https://blog.csdn.net/ysdaniel/article/details/6920866 或者 '/g' in.txt>out.txt
- Tunnel Warfare--- hdu1540 线段树求连续子区间
题目链接 题意:有n个村庄,编号分别为1-n:由于战争会破坏村庄,但是我们也会修复: D x代表村庄x被破坏: Q x是求与x相连的有几个没有被破坏: R 是修复最后一次被破坏的村庄: 接下来有m个操 ...
- 64位windows 7下配置TortoiseGit(转)
原文:http://our2848884.blog.163.com/blog/static/146854834201152325233854/ 最近感觉自己电脑上的代码太乱了,东一块.西一块……于是决 ...
- kubernetes实战(二十):k8s一键部署高可用Prometheus并实现邮件告警
1.基本概念 本次部署使用的是CoreOS的prometheus-operator. 本次部署包含监控etcd集群. 本次部署适用于二进制和kubeadm安装方式. 本次部署适用于k8s v1.10版 ...
- notefirst使用
1:如果格式不正确,导入题录失败的话,可以手动添加.点击新建题录即可.输入文章的标题等信息. 2:导入word中的文献,可以使用word中notefirst的引文编辑功能,对文献进行删除,编辑等. 3 ...
- vue-router中参数传递 && 编程式导航 && 坑 && beforeRouteEnter
第一部分: vue-router参数传递 通过router-link我们可以向路由到的组件传递参数,这在我们实际使用中时非常重要的. 路由: { path:"/DetailPage" ...
- thinkpad X1 extreme 安装Ubuntu 18.04.2 LTS
1.安装的时候需要禁用:nouveau.modeset=0 2.安装完成之后需要添加:acpi=off ,ro后面加上3,直接进入终端 3.启动之后:安装nvdia驱动 $ ubuntu-driver ...
- [LeetCode] 628. Maximum Product of Three Numbers_Easy
Given an integer array, find three numbers whose product is maximum and output the maximum product. ...
- ASIC中的一些库和文件类型
以下内容均来源于网络: 在进行综合,分析STA时,有几种库类型. NLDM: 非线性线载模型,最基本的dot lib. 电压源模型,cap值是单一值. 在90nm工艺以下,由于晶体管的特性变得很复杂 ...
- UVA10066
/* 最长公共子序列 */ #include <cstdio> #include <string.h> #include <iostream> const int ...