【POJ2352】【树状数组】Stars
Description

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
Output
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>
#include <algorithm>
#include <cstring>
#include <vector>
#include <utility>
#include <iomanip>
#include <string>
#include <cmath>
#include <map> const int MAXN = + ;
const int MAX = + ;
using namespace std;
struct DATA{
int x, y;
bool operator < (const DATA &b)const{
if (y == b.y) return x < b.x;
return y < b.y;
}
}data[MAXN];
int n, level[MAXN];
int C[MAX]; void init(){
memset(C, , sizeof(C));
scanf("%d", &n);
for (int i = ; i <= n; i++){
scanf("%d%d", &data[i].x, &data[i].y);
}
sort(data + , data + + n);
}
int lowbit(int x){return x & -x;}
void add(int x){
while (x <= ){
C[x]++;
x += lowbit(x);
}
}
int sum(int x){
int cnt = ;
while (x > ){
cnt += C[x];
x -= lowbit(x);
}
return cnt;
}
void work(){
memset(level, , sizeof(level));
for (int i = ; i <= n; i++){
level[sum(data[i].x + )]++;
add(data[i].x + );
}
for (int i = ; i < n; i++) printf("%d\n", level[i]);
} int main(){
#ifdef LOCAL
freopen("data.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
init();
work();
return ;
}
【POJ2352】【树状数组】Stars的更多相关文章
- poj2352树状数组
Astronomers often examine star maps where stars are represented by points on a plane and each star h ...
- [ACM_数据结构] POJ2352 [树状数组稍微变形]
Description Astronomers often examine star maps where stars are represented by points on a plane and ...
- poj2352树状数组解决偏序问题
树状数组解决这种偏序问题是很厉害的! /* 输入按照y递增,对于第i颗星星,它的level就是之前出现过的星星中,横坐标小于i的总数 */ #include<iostream> #incl ...
- hdu 1541 (基本树状数组) Stars
题目http://acm.hdu.edu.cn/showproblem.php?pid=1541 n个星星的坐标,问在某个点左边(横坐标和纵坐标不大于该点)的点的个数有多少个,输出n行,每行有一个数字 ...
- POJ-2352 Stars 树状数组
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39186 Accepted: 17027 Description A ...
- poj2352 Stars【树状数组】
Astronomers often examine star maps where stars are represented by points on a plane and each star h ...
- 【二维偏序】【树状数组】【权值分块】【分块】poj2352 Stars
经典问题:二维偏序.给定平面中的n个点,求每个点左下方的点的个数. 因为 所有点已经以y为第一关键字,x为第二关键字排好序,所以我们按读入顺序处理,仅仅需要计算x坐标小于<=某个点的点有多少个就 ...
- POJ 2352 Stars(树状数组)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 30496 Accepted: 13316 Descripti ...
- hdu 1541/poj 2352:Stars(树状数组,经典题)
Stars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- Stars(树状数组或线段树)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37323 Accepted: 16278 Description A ...
随机推荐
- suse linux 编译安装Apache时报“APR NOT FOUND”的解决方法
今日编译apache时出错: #./configure --prefix……检查编辑环境时出现: checking for APR... noconfigure: error: APR not fou ...
- vijosP1471 教主的游乐场
vijosP1471 教主的游乐场 链接:https://vijos.org/p/1471 [思路] 递推. 首先找到最左边的可以一步跳到后方的L, 那么L之后的点有两种情况:要么a足以跳到后方步数为 ...
- 2013.08.23.diary
Today, my baby called me.She said, she want to go abroad . And she wants me to go abroad too. I thin ...
- sshd_config 配置文件
Ssh-server 服务端 sshd_concfig Port Protocol HostKey /etc/ssh/ssh_host_rsa_key HostKey /etc/ssh/ssh_hos ...
- Archipelago - SGU 120(计算几何向量旋转)
题目大意:有一个正N边形,然后给出两个点,求出剩余的点的坐标. 分析:向量旋转可以求出坐标,顺时针旋转时候,x = x'*cos(a) + y'*sin(a), y=-x'*sin(a) + y'*c ...
- Conversion between json and object
public static string ObjToJson<T>(T obj) { DataContractJsonSerializer serializer = new DataCon ...
- UVa1151 Buy or Build
填坑(p.358) 以前天真的以为用prim把n-1条边求出来就可以 现在看来是我想多了 #include<cstdio> #include<cstring> #include ...
- RGB的三维模型与渐变色-颜色系列之一
一.前言 以下与颜色相关的日志记录了俺学习颜色的有关容,限于编写时的水平,难免存在缺点与错误,希望得到朋友.同行和前辈的指教,非常感谢.1. RGB的三维模型与渐变色-颜色系列之一2. <颜 ...
- Windows内核之线程的调度,优先级,亲缘性
1 调度 Windows不是实时操作系统,它是抢占式多线程操作系统.在如果全部优先级同样的情况下,CPU对线程的调度原则是每隔20m就会切换到下一个线程,依据Context中的IP和SP来接着运行上次 ...
- C# WinForm获取程序所在路径方法
多个获取WinForm程序所在文件夹路径的方法,收藏备忘. 1)获取当前进程的完整路径,包含文件名(进程名). 代码:string str =this.GetType().Assembly.Locat ...