HDU-1556:Color the ball(前缀和)
Color the ball
Time Limit: 9000/3000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 26275
Accepted Submission(s): 12734
当N = 0,输入结束。
随意举个例子,比如最开始c和d都是0,我们先涂1~3,则需要d[1]++,d[3+1]--;意味着第1个下标应该比第0个下标的c值多1(实际上是多了d[1],这里刚修改过一次所以是1),而第4个下标应该比第3个下标的c值少1(同上)。

假如这个时候没输入完,我们还不能就这么早求c。在上面的基础上再输入一组,涂2~3,显然这样子结束以后我们要输出的c是:1,2,2。试一下看看对不对。

希望这次的图示讲解能把前缀和的大概意思讲明白。这样子有兴趣的同学可以回去重做一下POJ3263,基本思路是一样的,只是区间开闭不同。
此次代码没有注释,因为上面已经解释得差不多了。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; int n,a,b;
int d[],c[]; int main()
{
while(~scanf("%d",&n)&&n)
{
memset(d,,sizeof(d));
memset(c,,sizeof(c));
for(int i=;i<=n;i++)
{
scanf("%d%d",&a,&b);
if(a>b) swap(a,b);
d[a]++;
d[b+]--;
}
for(int i=;i<=n;i++)
c[i]=c[i-]+d[i],printf("%d%c",c[i]," \n"[i==n]);
}
return ;
}
HDU-1556:Color the ball(前缀和)的更多相关文章
- HDU 1556 Color the ball 前缀和+思维
Color the ball N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球 ...
- hdu 1556:Color the ball(第二类树状数组 —— 区间更新,点求和)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1556:Color the ball(线段树,区间更新,经典题)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- HDU 1556 Color the ball (数状数组)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- 线段树(求单结点) hdu 1556 Color the ball
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1556 Color the ball(区间更新,单点求值)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU 1556 Color the ball(线段树区间更新)
Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...
- 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 Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/3276 ...
随机推荐
- 使用grunt js进行js的链接和压缩
1,http://nodejs.org/download/ 安装nodejs 2,配置环境变量,将nodejs的安装目录放置在Path环境变量中 3,在cmd中 npm install -g grun ...
- 闪动的Label控件
带闪动效果带控件,目前只有Label,以后会逐步增加,如果有好看带效果也欢迎您带加入. 如果可能,请在github中star,您的支持是我继续完善的动力,非常感谢. 测试环境:Xcode 5.0,iO ...
- 快速沃尔什变换(FWT)学习笔记 + 洛谷P4717 [模板]
FWT求解的是一类问题:\( a[i] = \sum\limits_{j\bigoplus k=i}^{} b[j]*c[k] \) 其中,\( \bigoplus \) 可以是 or,and,xor ...
- app基础
1界面:Layout 2.控件 3.整个窗口:Activity 4. ctrl + H : 查看类的继承关系 5. shift + F1:打开类的文档 6. Button button = (Butt ...
- jquery data 选择器 表格序列化serialize()
data()在元素上存放或者读取数据,返回jquery对象. demo: <div data-obj="{'name':'zhangsan','age':20}">&l ...
- ajax展示新页面同时传递参数
HTML页面部分代码: <div id="course" hidden></div> HTML页面中ajax代码: var selectType=$(&qu ...
- Redis的小白应用
在window下测试学习redis 步骤: 1.先下载安装 redis,(conf文件制定配置文件(redis-server.exe redis.conf ),若不指定则默认), 基本上我是直接点击 ...
- 使用 SourceTree 管理ios项目
SourceTree 是一个非常优秀的版本控制软件,他是一个客户端,方便我们去接入 GitHub .BitBucke 上面托管的代码. 声明(1——4是来自简书的非个人作品,仅仅保存资料学习使用) 一 ...
- git远程提交到github或者gitee
一.git安装 git官网下载 https://git-scm.com/downloads ,既有Windows的.Linux的以及Macos的. windowds下载安装git的可执行文件,就会有两 ...
- codevs-1204
1204 寻找子串位置 题目描述 Description 给出字符串a和字符串b,保证b是a的一个子串,请你输出b在a中第一次出现的位置. 输入描述 Input Description 仅一行包含两个 ...