题意:有一堆星星,每个星星的级别为坐标不高于它且不在它右边的星星个数,求级别为0~n - 1的星星个数。

解法:树状数组。输入的星星坐标已经按y坐标升序排序,y坐标相等的按x升序排序,所以每输入一个数只要看之前输入的星星里有几个x坐标小于等于它的x坐标即为它的等级,等级计数器加一,把这个星星的x坐标加入树状数组,最后扫一遍等级计数器输出。并没注意到x坐标有0这种坑爹的事情……果断T了……

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long
using namespace std;
int BA[32005];
int n;
inline int lowbit(int x)
{
return x & (-x);
}
void update(int pos)
{
for(int i = pos; i <= 32005; i += lowbit(i))
BA[i]++;
}
int query(int pos)
{
int res = 0;
for(int i = pos; i > 0; i -= lowbit(i))
res += BA[i];
return res;
}
int main()
{
while(~scanf("%d", &n))
{
memset(BA, 0, sizeof BA);
int ans[15005] = {0};
for(int i = 0; i < n; i++)
{
int x, y;
scanf("%d%d", &x, &y);
x++;
ans[query(x)]++;
//cout << "q = " << query(x) << endl;
update(x);
}
for(int i = 0; i < n; i++)
printf("%d\n", ans[i]);
}
return 0;
}

  

POJ 2352 Stars的更多相关文章

  1. poj 2352 Stars 数星星 详解

    题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...

  2. POJ 2352 Stars(线段树)

    题目地址:id=2352">POJ 2352 今天的周赛被虐了. . TAT..线段树太渣了..得好好补补了(尽管是从昨天才開始学的..不能算补...) 这题还是非常easy的..维护 ...

  3. POJ 2352 Stars(树状数组)

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

  4. 【树状数组】POJ 2352 Stars

    /** * @author johnsondu * @time 2015-8-22 * @type Binary Index Tree * ignore the coordinate of y and ...

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

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

  6. POJ 2352 Stars(HDU 1541 Stars)

    Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 41521   Accepted: 18100 Descripti ...

  7. [POJ] 2352 Stars [线段树区间求和]

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

  8. (简单) POJ 2352 Stars,Treap。

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

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

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

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

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

随机推荐

  1. Java内存区域与内存溢出异常(二)

    了解Java虚拟机的运行时数据区之后,大致知道了虚拟机内存的概况,内存中都放了些什么,接下来将了解内存中数据的其他细节,如何创建.如何布局.如何访问.这里虚拟机以HotSpot为例,内存区域以Java ...

  2. 微软Hololens学院教程-Hologram 230-空间场景建模(Spatial mapping )【微软教程已经更新,本文是老版本】

    这是老版本的教程,为了不耽误大家的时间,请直接看原文,本文仅供参考哦!原文链接:https://developer.microsoft.com/EN-US/WINDOWS/HOLOGRAPHIC/ho ...

  3. 小啃机器学习(1)-----ID3和C4.5决策树

    第一部分:简介 ID3和C4.5算法都是被Quinlan提出的,用于分类模型,也被叫做决策树.我们给一组数据,每一行数据都含有相同的结构,包含了一系列的attribute/value对. 其中一个属性 ...

  4. NSFileHandle 和 NSFileManager的一些用法

    文件操作 NSFileManager 常见的NSFileManager文件的方法: -(BOOL)contentsAtPath:path 从文件中读取数据 -(BOOL)createFileAtPat ...

  5. 1065: [NOI2008]奥运物流 - BZOJ

    Sample Input4 1 0.52 3 1 310.0 10.0 10.0 10.0Sample Output30.00 推荐题解:http://blog.csdn.net/whjpji/art ...

  6. 3123 高精度练习之超大整数乘法 - Wikioi

    题目描述 Description 给出两个正整数A和B,计算A*B的值.保证A和B的位数不超过100000位. 输入描述 Input Description 读入两个用空格隔开的正整数 输出描述 Ou ...

  7. nginx+ tomcat集群+动静资源分离

    不知道为什么这个随便删不掉,写了也值显示一半一半不显示, 我把重新写了一遍: nginx + tomcat集群和动静资源分离

  8. MySQL Replication 常用架构

    转自: http://www.cnblogs.com/ggjucheng/archive/2012/11/13/2768879.html 前言 MySQLReplicaion本身是一个比较简单的架构, ...

  9. [转载]jquery获取元素索引值index()方法:

    jquery的index()方法 搜索匹配的元素,并返回相应元素的索引值,从0开始计数. 如果不给 .index() 方法传递参数,那么返回值就是这个jQuery对象集合中第一个元素相对于其同辈元素的 ...

  10. hdu 3449

    有依赖的背包,转化成01背包来做: #include<iostream> #include<cstdio> #include<cstring> #include&l ...