hdoj--1556--Color the ball(模拟&&树状数组)
Color the ball
Total Submission(s): 13727 Accepted Submission(s): 6903
当N = 0,输入结束。
3
1 1
2 2
3 3
3
1 1
1 2
1 3
0
1 1 1
3 2 1
先来一组大神的代码,真神奇的模拟,思路太好了
#include<stdio.h>
#include<string.h>
int num[1000010];
int main()
{
int n;
while(scanf("%d",&n),n)
{
memset(num,0,sizeof(num));
int m=0;
for(int i=0;i<n;i++)
{
int a,b;
scanf("%d%d",&a,&b);
num[a]++;
num[b+1]--;
}
for(int i=1;i<n;i++)
{
m+=num[i];
printf("%d ",m);
}
printf("%d\n",m+num[n]);
}
return 0;
}
树状数组
#include<stdio.h>
#include<string.h>
int num[100010];
int n;
void add(int x,int k)
{
while(x>=1)
{
num[x]+=k;
x-=x&(-x);
}
}
int sum(int x)
{
int s=0;
while(x<=n)
{
s+=num[x];
x+=x&(-x);
}
return s;
}
int main()
{
while(scanf("%d",&n),n)
{
memset(num,0,sizeof(num));
for(int i=0;i<n;i++)
{
int a,b;
scanf("%d%d",&a,&b);
add(b,1);
add(a-1,-1);
}
for(int i=1;i<=n;i++)
{
if(i>1)
printf(" ");
printf("%d",sum(i));
}
printf("\n");
}
return 0;
}
hdoj--1556--Color the ball(模拟&&树状数组)的更多相关文章
- hdu 1556 Color the ball(树状数组)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556 题意:N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数[a,b]之间的气球 ...
- hdu 1556 Color the ball (树状数组)
Color the ballTime Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU 1556 Color the ball (树状数组 区间更新+单点查询)
题目链接 Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽&quo ...
- HDU 1556 Color the ball【树状数组】
题意:给出n个区间,每次给这个区间里面的数加1,询问单点的值 一维的区间更新,单点查询,还是那篇论文里面讲了的 #include<iostream> #include<cstdio& ...
- Color the ball(HDU1556)树状数组
每次对区间内气球进行一次染色,求n次操作后后所有气球染色次数. 树状数组,上下区间更新都可以,差别不大. 1.对于[x,y]区间,对第x-1位减1,第y位加1,之后向上统计 #include<b ...
- 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 线段树
题目链接:HDU - 1556 N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气 ...
- HD1556Color the ball(树状数组)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
随机推荐
- ACCESS-入门思维导图
ACCESS-入门思维导图 链接:http://pan.baidu.com/s/1bozYiNt 密码:5tly 如果有错误,请告知我!
- QT5 OpenGL (六, 键盘事件, 开关灯,放大缩小综合运用)
概要 实例效果图 立体图放大图 立体图缩小图 不加矢量开灯图 不加矢量关灯图 加矢量关灯图1 加矢量关灯图2 部分代码展示 主要内容解析 QT键盘事件 立体图形的放大和缩小 上下左右键以及A键D争键控 ...
- vue中export default 在console中是this.$vm
vue中export default 在console中是this.$vm 用vue-cli搭出框架,用webstorm进行开发,参考vue2的官网进行教程学习, 在vue-cli中是用es6的exp ...
- MFC 加入背景图片并让控件背景透明
/*加入背景图片*/ BOOL CTOOLDlg::OnEraseBkgnd(CDC* pDC) { // TODO: 在此加入消息处理程序代码和/或调用默认值 CDialog::OnEraseB ...
- sap abap 对字符串的操作
替换字段内容 REPLACE [FIRST /ALL OCCURRENCES OF]<STR1>INTO <STR> WITH <STR2> DATA STR ...
- How to get the MouseEvent coordinates for an element that has CSS3 Transform?
I want to detect where a MouseEvent has occurred, in coordinates relative to the clicked element. Wh ...
- html屏蔽鼠标右键
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 显示解析svg
g公司代码显示svg: SVGParserRenderer drawable = new SVGParserRenderer(context, String svgContent); String s ...
- kibana智能检索发送多次_msearch —— 配置index pattern,同时设置时间段,就知道到底是在哪些索引里去查找数据了
kibanasite/elasticsearch/log-*/_field_stats?level=indices 返回: {"_shards":{"total ...
- zzuoj--10401--物资调度(dfs)
A.物资调度 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 93 Solved: 52 [Submit][Status][Web Board] De ...