Stars

原创 2016年08月30日 13:43:26
链接:http://poj.org/problem?id=2352

题目: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.

题意:在坐标系的第一象限有几颗星星,每颗星星(m,n)的等级定义为满足(x<=m,y<=n)的星星的个数。

分析:所给的数据是按照y坐标升序的,其实是个提示,主要的思想就是要一层一层按照y轴去数。数据量中等,用暴力做的话,需要维护一个前缀和,我没试过,不过应该是可以做的,当时做的时候刚好学了树状数组,所以就用树状数组来做了。

题解:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <cmath>
#include <cctype>
#include <cfloat>
#include <climits>
#include <complex>
#include <deque>
#include <list>
#include <set>
#include <utility>
using namespace std;

int cla[32010];
int bit[32010];
pair<int,int> ps[32010];
int n;

void add(int x)
{
	while(x<=32005){
		bit[x]+=1;
		x+=x&-x;
	}
}

int countn(int x)
{
	int an=0;
	while(x){
		an+=bit[x];
		x-=x&-x;
	}
	return an;
}

int main()
{
	//freopen("in.txt","r",stdin);
	scanf("%d",&n);
	memset(bit,0,sizeof bit);
	memset(cla,0,sizeof cla);
	int x,y;
	for(int i=1;i<=n;i++){
		scanf("%d %d",&x,&y);
		add(x+1);
		cla[countn(x+1)-1]++;
	}
	for(int i=0;i<n;i++){
		printf("%d\n",cla[i]);
	}
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

视觉测量V-STARS系统

  • 2012-09-26 15:41
  • 140KB
  • 下载

CMG-STARS使用指南

  • 2010-06-19 17:08
  • 997KB
  • 下载

D - Stars

Description Astronomers often examine star maps where stars are represented by points on a plane ...

pku2482--Stars in Your Window

POJ 2352 Stars(简单树状数组)

什么是树状数组在这里就不说了啊,这里有解释了啊。http://blog.csdn.net/fulongxu/article/details/19701281 就是一个模版题目,直接套模版都可以过。先建...

hduoj Stars 二维树状数组

话说这道题是一道不折不扣的二维树状数组的水题,可是对于我这种菜鸟中的vip来说,却还是纠结了很久很久。。留下做个模板吧。。。。。 题目: Yifenfei is a romantic gu...

poj 2352 Stars(树状数组)

StarsDescriptionAstronomers often examine star maps where stars are represented by points on a plane...

POJ - 2352 Stars解题报告(树状数组求二维区域和)

题目大意:给你一个二维的坐标系(32000*32000),里面有n(15000)个点,告诉你每个点的坐标(各个点各不相同)。定义:(x0,y0)(x_0,y_0)的左下角区域为:{(x,y)(x,y)...

hdu 5533 Dancing Stars on Me

Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/O...

POJ 2352 stars

Description Astronomers often examine star maps where stars are represented by points on a plane ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)