Stars

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6993    Accepted Submission(s):
2754

Problem 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
给你一堆星星的坐标,一个星星的level等于它左下边的星星个数,不包括自己本身,可同x,同y;
而且题目给的星星的顺序是按照y,x坐标来排序的,BIT搞。
 /*******************************

 Date    : 2015-12-09 23:16:34
Author : WQJ (1225234825@qq.com)
Link : http://www.cnblogs.com/a1225234/
Name : ********************************/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
int bit[+];
int num[+];
int k=+;
int lowbit(int i)
{
return i&-i;
}
void add(int i,int a)
{
while(i<=)
{
bit[i]+=a;
i=i+lowbit(i);
}
}
int sum(int i)
{
int s=;
while(i>)
{
s+=bit[i];
i=i-lowbit(i);
}
return s;
}
int main()
{
freopen("in.txt","r",stdin);
int i,j;
int n,x,y;
while(scanf("%d",&n)!=EOF)
{
memset(num,,sizeof(num));
memset(bit,,sizeof(bit));
for(i=;i<n;i++)
{
scanf("%d%d",&x,&y);
num[sum(x+)]++;
add(x+,);
}
for(i=;i<n;i++)
printf("%d\n",num[i]);
}
return ;
}

据说暴力也能过:

 #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[],i,j,k,l,m,n,x[],y[];
int main()
{
while(scanf("%d",&k)!=EOF)
{
memset(a,,sizeof(a));
for(j=;j<k;j++)
{
scanf("%d%d",&x[j],&y[j]);
int cnt=;
for(l=;l<j;l++)
if(x[l]<=x[j])
cnt++;
a[cnt]++;
}
for(i=;i<k;i++)
printf("%d\n",a[i]); }
return ;
}
 

Stars(BIT树状数组)的更多相关文章

  1. POJ 2352 Stars(树状数组)

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

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

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

  3. POJ 2352 Stars(树状数组)题解

    Language:Default Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 52268 Accepted: 22 ...

  4. POJ 2352 stars (树状数组入门经典!!!)

    Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 54352   Accepted: 23386 Descripti ...

  5. Stars(树状数组)

    算法学习:http://www.cnblogs.com/George1994/p/7710886.html 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid ...

  6. poj2352 Stars【树状数组】

    Astronomers often examine star maps where stars are represented by points on a plane and each star h ...

  7. Ultra-QuickSort (求逆序数+离散化处理)、Cows、Stars【树状数组】

    一.Ultra-QuickSort(树状数组求逆序数) 题目链接(点击) Ultra-QuickSort Time Limit: 7000MS   Memory Limit: 65536K Total ...

  8. hdu 1541 Stars(树状数组)

    题意:求坐标0到x间的点的个数 思路:树状数组,主要是转化,根据题意的输入顺序,保证了等级的升序,可以直接求出和即当前等级的点的个数,然后在把这个点加入即可. 注意:树状数组下标从1开始(下标为0的话 ...

  9. 【HDU1514】Stars(树状数组)

    绝对大坑.千万记住树状数组0好下标位置是虚拟节点.详见大白书P195.其实肉眼看也能得出,在add(有的也叫update)的点修改操作中如果传入0就会死循环.最后TLE.所以下标+1解决问题.上代码! ...

  10. POJ 2352 Stars【树状数组】

    <题目链接> 题目大意: 题目给出n个点,这些点按照y坐标的升序,若y相同,则按照x的升序顺序输入,问,在这些点中,左下角的点的数量分别在0~n-1的点分别有多少个,写出它们的对应点数. ...

随机推荐

  1. Android-2

    传递简单数据 //发送方i.putExtra("data",t.getText().toString()); //接收方Intent i = getIntent();m = (Ed ...

  2. MongoDB备份数据库&导入数据库

    今天需要对线上的MongoDB中的webpage库进行备份,然后在本地导入备份的库. 1.备份整个MongoDB数据库 mongodump -h dbhost --port 端口 -u 用户名 -p ...

  3. Verilog 模块参数重定义(转)

    Verilog重载模块参数: 当一个模块引用另外一个模块时,高层模块可以改变低层模块用parameter定义的参数值,改变低层模块的参数值可采用以下两种方式: 1)defparam 重定义参数语法:d ...

  4. Android AsyncTask 异步任务操作

    1:activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/androi ...

  5. Oracle 安装时候的网络相关内核参数

    http://www.cnblogs.com/gaojian/archive/2012/10/12/2721284.html http://blog.chinaunix.net/uid-2442641 ...

  6. Delphi的核心优势:三快一多

    快是指:开发快(RAD开发),编译快(好像是没有用到LL(1),从而避免了潜在的歧义),运行快(原生代码). 多是指:开发符合PME标准的可视化控件,易开发,易使用,所以第三方控件特别多,这个不用解释 ...

  7. 转:PHP的(Thread Safe与Non Thread Safe)

    在安装xdebug到时候你会有有TS和NTS版本的选择,在以前还有VC6和VC9的版本.如果你没有根据你目前的服务器的状况选择对应的版本的话,那么xdebug是安装不成功的. 一.如何选择 php5. ...

  8. UML--一些图

    通过UML来表示汽车,简洁明了. 统一建模语言--UML. 参与者Actor,参与者代表了现实世界的人.人. 用例use case,就是参与者要做什么并且获得什么.事. 业务场景,用例场景.规则. 业 ...

  9. 转:更新Android SDK之后Eclipse提示ADT版本过低的一个简易解决办法

    拜GFW所赐,对于初学者的我来说,总会出现一些莫名其妙的问题 首先说明一下发表这一篇博文的“历史原因”吧,因为在更新SDK之后,进入Eclipse设置Android SDK目录的时候,会突然说我的版本 ...

  10. heritrix 3.2.0 -- 环境搭建

    heritrix作为一个比较经典的开源爬虫,写这篇文章目的是因为,3.X之后的heritrix的介绍以及配置的文章比较少了. heritrix 3.x 以后使用maven 2配置jar包引用,但是总是 ...