Stars(树状数组)
http://acm.hdu.edu.cn/showproblem.php?pid=1541
Stars
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5993 Accepted Submission(s): 2384

For example, look at the map shown on the figure above. Level of the star number 5 is equal to 3 (it's formed by three stars with a numbers 1, 2 and 4). And the levels of the stars numbered by 2 and 4 are 1. At this map there are only one star of the level 0, two stars of the level 1, one star of the level 2, and one star of the level 3.
You are to write a program that will count the amounts of the stars of each level on a given map.
1 1
5 1
7 1
3 3
5 5
2
1
1
0
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <cstring> using namespace std; int n;
const int N=;
const int M=; int a[M],c[N]; int lowbit(int t)
{
return t&(-t);
} void insert(int t,int d)
{
while (t<=M)
{
a[t]+=d;
t+=lowbit(t);
}
} int getsum(int t)
{
int zs=;
while (t>)
{
zs+=a[t];
t-=lowbit(t);
}
return zs;
} int main()
{
int i,x,y,p,n;
while (scanf("%d",&n)!=EOF)
{
memset(a,,sizeof(a));
memset(c,,sizeof(c));
for (i=;i<=n;i++) {
scanf("%d%d",&x,&y);
insert(x+,);
p=getsum(x+)-;
c[p]++;
}
for (i=;i<n;i++) printf("%d\n",c[i]);
}
return ;
}
Stars(树状数组)的更多相关文章
- POJ-2352 Stars 树状数组
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39186 Accepted: 17027 Description A ...
- Stars(树状数组或线段树)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37323 Accepted: 16278 Description A ...
- Stars(树状数组单点更新)
Astronomers often examine star maps where stars are represented by points on a plane and each star h ...
- HDU-1541 Stars 树状数组
题目链接:https://cn.vjudge.net/problem/HDU-1541 题意 天上有许多星星 现给天空一个平面坐标轴,统计每个星星的level, level是指某一颗星星的左下角(x& ...
- POJ 2352 && HDU 1541 Stars (树状数组)
一開始想,总感觉是DP,但是最后什么都没想到.还暴力的交了一发. 然后開始写线段树,结果超时.感觉自己线段树的写法有问题.改天再写.先把树状数组的写法贴出来吧. ~~~~~~~~~~~~~~~~~~~ ...
- hdu1541 Stars 树状数组
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 题目大意就是统计其左上位置的星星的个数 由于y已经按升序排列,因此只用按照x坐标生成一维树状数组 ...
- Stars(树状数组+线段树)
Stars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- POJ2352 Stars 树状数组
emm,ssy说可以直接CDQ分治...%%%但是注意到y是有序的,所以可以直接求一下前缀和就行了. 题干: Astronomers often examine star maps where sta ...
- POJ2352 Stars [树状数组模板]
题意:输入一n颗星星的x,y坐标,给定判断level的标准,即某颗星星左下边(不高于它,不超过他,相当于以他为基准的第三象限)星星的数目为level, 输出level从0到n的星星个数. //poj2 ...
随机推荐
- ArcGIS API for JavaScript 4.2学习笔记[18] 搜索小部件
这个例子很简单,作为开学后(暴露出学生党的本质)的开胃菜是再合适不过了. 不过,博主提前警告一下:接下来的例子会相当的长.烦.难.我还会用"引用"-"函数参数骨架&quo ...
- 程序员的自我救赎---10.1:APP版本控制系统
<前言> (一) Winner2.0 框架基础分析 (二)PLSQL报表系统 (三)SSO单点登录 (四) 短信中心与消息中心 (五)钱包系统 (六)GPU支付中心 (七)权限系统 (八) ...
- lesson - 14 linux系统日常管理3
1. Linux系统服务管理工具ntsysv 类似图形界面管理工具,如果没有该命令使用 yum install -y ntsysv 安装常用服务:crond, iptables, network, s ...
- ActiveMQ (三) 讯息传送机制以及ACK机制
详析请看如下博客: http://blog.csdn.net/lulongzhou_llz/article/details/42270113 后续再做整理.
- DJango_生命周期
在django中,当我们访问一个url时,会通过路由匹配进入到响应的html页面中. Django的生命周期,指的就是当用户在浏览器上输入url,到用户看到整个页面之前,django后台都做了哪些事情 ...
- window10上登录Oracle时提示ORA-12546:Permission denied
在64位的Windows 10上安装了Oracle 10.2.0.4的64位版,遇到不少问题. 虽然可能现在安装这个版本越来越少,还是分享出来,希望能帮助到一些人. 1.安装的过程遇到的问题 在普通用 ...
- [代码审计]青云客Cms前台有条件注入至getshell,后台xss至getshell、至弹你一脸计算器
之前写了一篇关于青云客cms的文章,发在了t00ls,就不copy过来了. 给个链接,好记录一下. https://www.t00ls.net/thread-43093-1-1.html
- Elasticsearch Head插件实践
简介 Elasticsearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.Elasticsearch是用Java开发的,并作为Ap ...
- easy ui Tree请求跨域数据
扯淡篇: jQuery EasyUI为提供了大多数UI控件的使用,如:accordion,combobox,menu,dialog,tabs,validatebox,datagrid,window,t ...
- 利用树莓派实现监控系统二(用motion实现监控)
终于要开始实现监控啦!ಠ౪ಠ 看起来很简单的步骤,但是过程却无比艰辛,踩坑是最好的成长 (/= _ =)/~┴┴ 第一步,不是安装!而是 update!ㄟ( ▔, ▔ )ㄏ sudo apt-get ...