Color the ball HDOJ--1556
Color the ball
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6609 Accepted Submission(s): 3468
当N = 0,输入结束。
思路:线段树题目,感觉是时候学学线段树这种数据结构了,于是找了一题练练,一次AC,爽啊!
成断更新,单点查询!
AC代码:
#include<stdio.h>
#define MAX 100001
typedef struct
{
int left;
int right;
int cover;
}Node;
Node ball[*MAX];
int cnt;
void build(int l,int r,int k)
{
int mid;
if(l == r)
{
ball[k].left = l;
ball[k].right = r;
ball[k].cover = ;
return ;
}
ball[k].left = l;
ball[k].right = r;
ball[k].cover = ;
mid = (l+r) >> ;
build(l,mid,k << );
build(mid+,r,k << |);
} void insert(int l,int r,int k)
{
if(l == ball[k].left && r == ball[k].right)
{
ball[k].cover++;
return ;
}
if(ball[k].right == ball[k].left)
return ;
int mid = (ball[k].left+ball[k].right) >> ;
if(r <= mid)
insert(l,r,k << );
else if(l > mid)
insert(l,r,k << |);
else
{
insert(l,mid,k << );
insert(mid+,r,k << |);
}
return ;
} void search(int num,int k)
{
if(ball[k].left == ball[k].right)
{
cnt += ball[k].cover;
return ;
}
cnt += ball[k].cover;
int mid = (ball[k].left+ball[k].right) >> ;
if(num <= mid)
search(num,k << );
else
search(num,k << |);
return ;
} int main()
{
int n,i;
int a,b;
while(~scanf("%d",&n) && n)
{
build(,n,);
for(i = ;i < n;i ++)
{
scanf("%d%d",&a,&b);
insert(a,b,);
}
for(i = ;i < n;i ++)
{
cnt = ;
search(i,);
printf("%d ",cnt);
}
cnt = ;
search(n,);
printf("%d\n",cnt);
}
return ;
}
Color the ball HDOJ--1556的更多相关文章
- Color the ball HDU - 1556 (非线段树做法)
题意:在1到n的气球中,在不同的区域中涂颜色,问每个气球涂几次. #include<cstdio>int num[100010];int main(){ int n, x, y;; whi ...
- Color the ball HDU - 1556 (线段树)
思路:线段树,区间更新 #include<iostream> #include<vector> #include<string> #include<cmath ...
- A - Color the ball HDU - 1556 (差分数组+前缀和)
思路等引自博客 https://blog.csdn.net/johnwayne0317/article/details/84928568 对数组a[7]: a[0]=1; = d[0] a[1]=1; ...
- 树状数组模板--Color the ball
Color the ball HDU - 1556 N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电 ...
- hdoj 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 (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- 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)To ...
随机推荐
- xcode编译运行报错纪录(持续更新)
---恢复内容开始--- 1. Undefined symbols for architecture i386: "_deflate", referenced from: -[NS ...
- Xcode 7 支持http请求info.plist设置
由于iOS9改用更安全的https,为了能够在iOS9中正常使用http发送网络请求,请在"Info.plist"中进行如下配置,否则影响SDK的使用. 1.找到项目中的 Info ...
- Java实战之01Struts2-04拦截器、上传下载、OGNL表达式
十二.Struts2中的拦截器 1.拦截器的重要性 Struts2中的很多功能都是由拦截器完成的.比如:servletConfig,staticParam,params,modelDriven等等. ...
- 滑动条 Trackbar[OpenCV 笔记9]
OpenCV中没有实现按钮的功能,我们可以利用滑动条来实现按钮功能. , ); trackbarname 轨迹条的名字. winname 窗口的名字,轨迹条会依附在这个窗口上. value 一个指向整 ...
- java.util.Map源码分析
/** * An object that maps keys to values. A map cannot contain duplicate keys; * each key can map to ...
- QT5.0.1在Windows下 出现QApplication: No such file or directory 问题的解决办法
第一个Qt 程序 环境window ,ide qt creator 新建一个 C++ 项目 > 新建一个main.cpp 输入如下代码 #include<QApplication> ...
- nginx 限制及指定IP或IP段访问
nginx 限制及指定IP或IP段访问. location / { deny 192.168.1.1; allow ; allow ; deny all; } 企业问题案例:Nginx做反向代理的时候 ...
- 关于ubuntu上执行错误命令报错
Sorry, command-not-found has crashed! 新安装了一台ubuntu server 安装时用中文安装的,之后命令行下各种乱码,最后也不知道是修改哪里造成的 每次执行一次 ...
- JS进制转换,浮点数相加,数字判断
document.write("整数转换函数:parseInt(数据,底数)<br>"); document.write("10101=>" ...
- win7的IE11降到IE8
我为什么要降低IE版本呢?...... 下载了抓包工具HttpWatch,下载地址http://pan.baidu.com/s/1kVhPMmj 版本如下: 用IE11打开抓包时流内没有内容,可能跟 ...