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. DataTables获取表单输入框数据

    $(document).ready(function() { var table = $('#example').DataTable(); $('button').click(function() { ...

  2. IOS 推送原理

    最近两天在研究ios的消息推送机制.研究这个东西,还是充满兴趣的. Push的原理: Push 的工作机制可以简单的概括为下图 图中,Provider是指某个iPhone软件的Push服务器,这篇文章 ...

  3. (转)syslog日志等级

    设施.优先级”(facility.priority)设施(facility): kern 0 内核日志消息 user 1 随机的用户日志消息 mail 2 邮件系统日志消息 daemon 3 系统守护 ...

  4. final关键字的作用

    final 可以修饰类.方法.变量. (1):final修饰的变量是一个常量,只能被赋值一次. 常量一般使用final声明,如: public static final String CHINA = ...

  5. Ext4.0.7使用Ext.grid.ColumnModel报错:TypeError: Ext.grid.Model is not a constructor

    代码如下: Ext.onReady(function(){ //定义列 var cm = new Ext.grid.ColumnModel([ {header: '编号', dataIndex: 'i ...

  6. 决策树之ID3算法实现(python)

    决策树的概念其实不难理解,下面一张图是某女生相亲时用到的决策树: 基本上可以理解为:一堆数据,附带若干属性,每一条记录最后都有一个分类(见或者不见),然后根据每种属性可以进行划分(比如年龄是>3 ...

  7. 最小费用最大流模板 poj 2159 模板水题

    Going Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15944   Accepted: 8167 Descr ...

  8. 异步套接字基础:select函数以及FD_ZERO、FD_SET、FD_CLR、FD_ISSET

    参考:[原创]技术系列之 网络模型(三)多路复用模型 select函数 select函数: 系统提供select函数来实现多路复用输入/输出模型.原型: #include <sys/time.h ...

  9. 《Java程序员面试笔试宝典》终于在万众期待中出版啦~

    <Java程序员面试笔试宝典>终于在万众期待中出版啦~它是知名畅销书<程序员面试笔试宝典>的姊妹篇,而定价只要48元哦,恰逢求职季节,希望本书的出版能够让更多的求职者能够走进理 ...

  10. Linux Security模块

    一.Linux Security Modules Linux Security Modules (LSM) 是一种 Linux 内核子系统,旨在将内核以模块形式集成到各种安全模块中.在 2001 年的 ...