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. mysql点滴_02程序中运行sql语句报字符集问题解决

    程序中运行  "SELECT t.EVENT_TYPE_ID FROM RATABLE_EVENT_TYPE t WHERE t.NAME='帐期末费用转移事件'"  报错 错误码 ...

  2. 韩国IT业是怎么走向国际我们须要学习什么

    无论从国土面积仍是从人口数量上来衡量.韩国都不能算是一个大国,而且自然资本十分缺乏,即是在这种情况下,韩国经过几十年的尽力开展变成技能大国,格外是在IT这种新经济范畴更是引人注目.并诞生了三星等国际级 ...

  3. hdu 5410 CRB and His Birthday 01背包和全然背包

    #include<stdio.h> #include<string.h> #include<vector> #include<queue> #inclu ...

  4. java中文件路径读取

    windows下 1)相对路径 public static final String TestDataExcelFilePath="src/omstestdata.xlsx"; 2 ...

  5. java连接sql server

    package com.cps.rom.utils; /************************************************************************ ...

  6. 【Hibernate步步为营】--单向关联一对一映射

    上篇文章对多对一的关联映射做了具体的分析,它在实现上能够有两种方式,而且这两种方式实现也非常easy,关键是标签<many-to-one>的使用,它分别指明了多端和一端的映射关系.这样的映 ...

  7. 更改python字符编码以便使用UTF-8的编码url路径

    url编码分两种, 一种是unicode, 另一种是gb2312, 今天遇到的一个网站是要将字符编码按照gb2312来编码,用来得到一个先填写blanks后再返回页面的数据,废话少说,需要做的就是先查 ...

  8. windows2003安装

    产品密钥JCDPY-8M2V9-BR862-KH9XB-HJ3HMiis的i386文件夹http://pan.baidu.com/s/1dD0EY6twindows2003的iso映像http://p ...

  9. javascript动画函数封装(升级版)

    //把 任意对象 的 任意数值属性 改变为 任意的目标值 function animate(obj, json, fn) { clearInterval(obj.timer); obj.timer = ...

  10. javascript一个重要知识点:事件。

    javascript是事件驱动的,那什么是事件?事件就是在javascript中被侦测到DOM元素行为,就称之为javascript事件. 2.事件的三个阶段 事件的三个阶段分别为: 1.捕获阶段 2 ...