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. form 练习

    <form>姓:<input type="text" name="firstname" /><br />名:<inpu ...

  2. CPU的物理限制

    Quote from Solidot 密歇根大学的Igor Markov在上周的<自然>期刊上发表了一篇文章,谈论了CPU面临的基本物理限制.有学者曾估计预言CPU晶体管数目和性能增长的摩 ...

  3. 判断一个key 是否在map中存在

    public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-gener ...

  4. poj1410

    简单题,注意是实心矩形 #include <iostream> #include <math.h> #include <iomanip> #define eps 1 ...

  5. Android恢复出厂设置流程分析【Android源码解析十】

    最近看恢复出厂的一个问题,以前也查过这方面的流程,所以这里整理一些AP+framework层的流程: 在setting-->备份与重置--->恢复出厂设置--->重置手机---> ...

  6. 继承之后的使用注意事项_ArrayStoreException

    今天在看Core In Java第五章节时,看到一个很感兴趣的知识点,如下: 在Java中,子类数组的引用可以转换成超类数组的引用,而不需要采用强制转换.但是,在超类数组的引用添加超类类型引用对象之后 ...

  7. css基本选择器

    CSS:层叠样式表 (Cascading Style Sheets) 结构层:HTML表现层: CSS行为层: DOM,JavaScript CSS语法结构:div{background:#f00;} ...

  8. Func 委托 和 Action 委托 初步谈论

    继上篇EventHandler之后,继续填坑,简单了解下Func<TResult> 委托 和 Action 委托. msdn对于两者的解释: Func<TResult>:封装一 ...

  9. oracle索引学习

    查看执行状态: 选中代码直接按F5,或者点击Tools===>>Explain Plan 一.索引的注意事项: 当任何单个查询要检索的行少于或者等于整个表行数的10%时,索引就非常有用.这 ...

  10. java 加载图片的几种方式

    项目目录--src--testTable--image--active.gif | |_Task.class 方法1:通过项目目录访问. String a = System.getProperty(& ...