http://poj.org/problem?id=2352

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 46592   Accepted: 20096

Description

Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given star. Astronomers want to know the distribution of the levels of the 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

The first line of the input file contains a number of stars N (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

The output should contain N lines, one number per line. The first 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

This problem has huge input data,use scanf() instead of cin to read data to avoid time limit exceed.

Source

 
 
树状数组的应用
可以先把星星按照从左到右,从下到上排序
然后把每个星星的级别存到树状数组中就可以了
 #include <algorithm>
#include <cstdio> #define lowbit(x) (x&(-x)) using namespace std; const int N();
const int N_();
int n;
struct TypeNodeStar
{
int x,y;
}star[N]; bool cmp(TypeNodeStar a,TypeNodeStar b)
{
if(a.x!=b.x) return a.x<b.x;
return a.y<b.y;
} int c[N_];
int ans[N],t[N_]; int query(int x)
{
int ans=;
for(;x;x-=lowbit(x)) ans+=t[x];
return ans;
} void insert(int x)
{
for(;x<=N_;x+=lowbit(x)) t[x]++;
} int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d%d",&star[i].x,&star[i].y);
star[i].x++; star[i].y++;
}
sort(star+,star+n+,cmp);
for(int i=;i<=n;i++)
{
int tmp=query(star[i].y);
insert(star[i].y);
ans[tmp]++;
}
for(int i=;i<n;i++) printf("%d\n",ans[i]);
return ;
}

POJ——T2352 Stars的更多相关文章

  1. poj 2352 Stars 数星星 详解

    题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...

  2. poj 2482 Stars in Your Window(扫描线)

    id=2482" target="_blank" style="">题目链接:poj 2482 Stars in Your Window 题目大 ...

  3. POJ 2482 Stars in Your Window(线段树)

    POJ 2482 Stars in Your Window 题目链接 题意:给定一些星星,每一个星星都有一个亮度.如今要用w * h的矩形去框星星,问最大能框的亮度是多少 思路:转化为扫描线的问题,每 ...

  4. [poj P2482] Stars in Your Window

    [poj P2482] Stars in Your Window Time Limit: 1000MS  Memory Limit: 65536K Description Fleeting time ...

  5. POJ 2352 Stars(树状数组)

    Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30496   Accepted: 13316 Descripti ...

  6. poj 2482 Stars in Your Window + 51Nod1208(扫描线+离散化+线段树)

    Stars in Your Window Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13196   Accepted:  ...

  7. poj 2482 Stars in Your Window (线段树:区间更新)

    题目链接:http://poj.org/problem?id=2482 读完题干不免有些心酸(

  8. hdu 1541/poj 2352:Stars(树状数组,经典题)

    Stars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  9. 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 ...

随机推荐

  1. UVa11183 - Teen Girl Squad(最小树形图-裸)

    Problem I Teen Girl Squad  Input: Standard Input Output: Standard Output -- 3 spring rolls please. - ...

  2. [Angular] Service Worker Version Management

    If our PWA application has a new version including some fixes and new features. By default, when you ...

  3. 1003. 我要通过!(20) (ZJUPAT 模拟)

    题目链接:http://pat.zju.edu.cn/contests/pat-b-practise/1003 "答案正确"是自己主动判题系统给出的最令人欢喜的回复.本题属于PAT ...

  4. mysql基础综述(四)

    1.数据库的简单介绍 1.1 数据库,就是一个文件系统,使用标准sql对数据库进行操作 1.2 常见的数据库 oracle  是oracle公司的数据库,是一个收费的大型的数据库 DB2,是IBM公司 ...

  5. Shiro 学习应用(续)

    在前面的文章中为大家介绍了 Shrio 的基础概念.可能比較笼统.没有深入到开发过程的一些问题.如今集中在本帖中归纳一下有关问题. FormAuthenticationFilter 表单过滤器 表单过 ...

  6. 2014.04.16,读书,读书笔记-《Matlab R2014a完全自学一本通》-第17章 图形用户界面

    界面对象分三类: 用户控件对象(uicontrol) 下拉式菜单对象(uimenu) 内容式菜单对象(uicontextmenu) 创建用户界面: 1.命令行方式 采用uicontrol来创建控件对象 ...

  7. Codeforces Gym 100015F Fighting for Triangles 状态压缩DP

    F Fighting for Triangles Description Andy and Ralph are playing a two-player game on a triangular bo ...

  8. mysqli的简单工具包

    mysqli的简单工具包 <?php /** * 连接 * @param string $host * @param string $user * @param string $password ...

  9. poj--3159--Candies(简单差分约束)

    Candies Time Limit: 1500MS   Memory Limit: 131072K Total Submissions: 26888   Accepted: 7398 Descrip ...

  10. 【POJ 2482】 Stars in Your Windows

    [题目链接] http://poj.org/problem?id=2482 [算法] 线段树 + 扫描线 [代码] #include <algorithm> #include <bi ...