Stars
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.
Input
(1<=N<=15000). The following N lines describe coordinates of stars
(two integers X and Y per line separated by a space,
0<=X,Y<=32000). There can be only one star at one point of the
plane. Stars are listed in ascending order of Y coordinate. Stars with
equal Y coordinates are listed in ascending order of X coordinate.
Output
line contains amount of stars of the level 0, the second does amount of
stars of the level 1 and so on, the last line contains amount of stars
of the level N-1.
Sample Input
5
1 1
5 1
7 1
3 3
5 5
Sample Output
1
2
1
1
0
Hint
#include <iostream>
#include <cstdio>
using namespace std;
int n,x,y;
int tree[],level[];
int lowbit(int t)
{
return t&-t;
}
void update(int x,int y)
{
for(int i = x;i <= ;i += lowbit(i))
{
tree[i] += y;
}
}
int gettree(int x)
{
int ans = ;
for(int i = x;i > ;i -= lowbit(i))
{
ans += tree[i];
}
return ans;
}
int main()
{
scanf("%d",&n);
for(int i = ;i < n;i ++)
{
scanf("%d%d",&x,&y);
x ++;
level[gettree(x)] ++;
update(x,);
}
for(int i = ;i < n;i ++)
{
printf("%d\n",level[i]);
}
}
Stars的更多相关文章
- poj 2352 Stars 数星星 详解
题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
- POJ 2352 Stars(树状数组)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 30496 Accepted: 13316 Descripti ...
- 【POJ-2482】Stars in your window 线段树 + 扫描线
Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11706 Accepted: ...
- Java基础之在窗口中绘图——填充星型(StarApplet 2 filled stars)
Applet程序. import javax.swing.*; import java.awt.*; import java.awt.geom.GeneralPath; @SuppressWarnin ...
- XidianOJ 1177 Counting Stars
题目描述 "But baby, I've been, I've been praying hard, Said, no more counting dollars We'll ...
- POJ-2352 Stars 树状数组
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39186 Accepted: 17027 Description A ...
- hdu 1541/poj 2352:Stars(树状数组,经典题)
Stars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- POJ 2482 Stars in Your Window 线段树扫描线
Stars in Your Window Description Fleeting time does not blur my memory of you. Can it really be 4 ...
- 2015ACM/ICPC亚洲区长春站 G hdu 5533 Dancing Stars on Me
Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- Stars(树状数组或线段树)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37323 Accepted: 16278 Description A ...
随机推荐
- APP测试的要点
APP测试要点 功能性 UI界面 安装与卸载 升级 登录测试 离线测试 安全性测试 兼容性(操作系统,屏幕尺寸,分辨率,厂家) 消息推送 前后台切换 网络环境(wifi/2G/3G/4G/无网) 异常 ...
- adb 不设别解决方案
1.当然首先你得将手机里的usb debug选项选上,否则lsusb是不会有你的设备的 2. lsusb 查看usb设备id 3. sudo vim /etc/udev/rules.d/51-andr ...
- Servlet容器初始化IOC容器
<!-- ServletContext参数,配置Ioc容器的xml文件名 --> <context-param> <param-name>contextConfig ...
- tomcat常用配置详解和优化方法
tomcat常用配置详解和优化方法 参考: http://blog.csdn.net/zj52hm/article/details/51980194 http://blog.csdn.net/wuli ...
- tyvj 1056 能量项链 区间dp
P1056 能量项链 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 NOIP2006 提高组 第一道 描述 在Mars星球上,每个Mars人都随身佩 ...
- TiDB 在摩拜单车的深度实践及应用
一.业务场景 摩拜单车 2017 年开始将 TiDB 尝试应用到实际业务当中,根据业务的不断发展,TiDB 版本快速迭代,我们将 TiDB 在摩拜单车的使用场景逐渐分为了三个等级: P0 级核心业务: ...
- LeetCode第[50]题(Java):Pow(x, n)
题目:求x的n次幂 难度:Medium 题目内容: Implement pow(x, n), which calculates x raised to the power n (xn). 翻译: 实现 ...
- jQuery中hover和blur使用代理delegate无效的解决方法
今天就遇到了这样的小问题: $(document).ready(function(){ $('.status_on').hover(function(){ $(this).html('点击禁用'); ...
- 从Activity中返回数据
从Activity中返回数据 一.简介 这里也就是使用intent方式返回数据. 二.具体步骤 在MainActivity通过一个button访问Activity01页面,然后将Activity01页 ...
- appium自动化测试(二)
一. 获取应用包名和入口activity 获取应用包名和入口activity:aapt命令 aapt目录: 安卓sdk的build-tools目录下(如果要在cmd里直接运行,要配置环境变量,否则需要 ...