POJ 2352 Stars

来源:互联网 发布:淘宝宝贝描述上传图片 编辑:程序博客网 时间:2024/06/05 05:40
http://poj.org/problem?id=2352
感觉这道题目的意思不太好理解,简单的说就是给你一些点的坐标(星的坐标)对于每个星星有等级的划分,那怎么划分等级呢?  规则是对于星(x,y)满足x'<=x&&y'<=y的(x',y')有几个那么星(x,y)就是几级。如样例给的那样。输出0~n-1级每级星的个数。(由于题目中说了每个星y是是递增输入的问题就更容易些)
解题思路:a[i]数组存i级的星星数目。树状数组用来求和,更改。
就是求它前面比它小的个数.

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>

#define maxn 1000010
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<30
const ull inf = 1LL << 61;
const double eps=1e-5;

using namespace std;

bool cmp(int a,int b){
return a>b;
}
int a[32005],c[32005];
int n;
int lowbit(int i)
{
return i&(-i);
}
void add(int i,int d)
{
while(i<=32002)
{
c[i]+=d;
i+=lowbit(i);
}
}
int sum(int i)
{
int ret=0;
while(i>0)
{
ret+=c[i];
i-=lowbit(i);
}
return ret;
}
int x,y;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(cin>>n&&n)
{
cle(c),cle(a);
for(int i=1;i<=n;i++)
{
scanf("%d%d",&x,&y);
++x;
a[sum(x)]++;
add(x,1);
}
for(int i=0;i<n;i++)
printf("%d\n",a[i]);
}
return 0;
}


Stars
Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 33886Accepted: 14776

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. 
POJ 2352 Stars - 风未定 - Principal Guan

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

51 15 17 13 35 5

Sample Output

12110

Hint

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

Source

Ural Collegiate Programming Contest 1999
0 0
原创粉丝点击