Stars(BIT树状数组)
Stars
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6993 Accepted Submission(s):
2754
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.
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.
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.
/******************************* 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树状数组)的更多相关文章
- POJ 2352 Stars(树状数组)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 30496 Accepted: 13316 Descripti ...
- hdu 1541/poj 2352:Stars(树状数组,经典题)
Stars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- POJ 2352 Stars(树状数组)题解
Language:Default Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 52268 Accepted: 22 ...
- POJ 2352 stars (树状数组入门经典!!!)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 54352 Accepted: 23386 Descripti ...
- Stars(树状数组)
算法学习:http://www.cnblogs.com/George1994/p/7710886.html 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid ...
- poj2352 Stars【树状数组】
Astronomers often examine star maps where stars are represented by points on a plane and each star h ...
- Ultra-QuickSort (求逆序数+离散化处理)、Cows、Stars【树状数组】
一.Ultra-QuickSort(树状数组求逆序数) 题目链接(点击) Ultra-QuickSort Time Limit: 7000MS Memory Limit: 65536K Total ...
- hdu 1541 Stars(树状数组)
题意:求坐标0到x间的点的个数 思路:树状数组,主要是转化,根据题意的输入顺序,保证了等级的升序,可以直接求出和即当前等级的点的个数,然后在把这个点加入即可. 注意:树状数组下标从1开始(下标为0的话 ...
- 【HDU1514】Stars(树状数组)
绝对大坑.千万记住树状数组0好下标位置是虚拟节点.详见大白书P195.其实肉眼看也能得出,在add(有的也叫update)的点修改操作中如果传入0就会死循环.最后TLE.所以下标+1解决问题.上代码! ...
- POJ 2352 Stars【树状数组】
<题目链接> 题目大意: 题目给出n个点,这些点按照y坐标的升序,若y相同,则按照x的升序顺序输入,问,在这些点中,左下角的点的数量分别在0~n-1的点分别有多少个,写出它们的对应点数. ...
随机推荐
- 64位Ubuntu14.04搭建ADT开发环境
本来放假是要出去玩的,结果出游计划拖到了周一,今天先来无事看看ubuntu最近发展得怎么样了,顺便把ADT也搭建好,方便以后研究android框架.想想在windows下,ADT直接down下来解压就 ...
- jquery中checkbox全选失效的解决方法
这篇文章主要介绍了jquery中checkbox全选失效的解决方法,需要的朋友可以参考下 如果你使用jQuery 1.6 ,代码if ( $(elem).attr(“checked”) ),将 ...
- qemu cow镜像分析
最近研究了以下qemu最简单的read on direct 镜像格式cow,在稀疏文件的模式下,这种方式还是比较简单,而且有优势的.其优势主要体现在云计算环境中,不需要用到qcow2的那些诸如内部快照 ...
- BZOJ 1090 字符串折叠(区间DP)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1090 题意:字符串AAAAAAAAAABABABCCD的最短折叠为9(A)3(AB)CC ...
- mysql/Java服务端对emoji的支持
更改好后的字符集: 乱码 推荐大家看 深入MySQL字符集设置 ,区分检查client端.server端的编码:最简单暴力的方式,是在所有的环节都显式明确的指定相同的编码. 比如使用python的My ...
- Hdu3640-I, zombie(模拟+二分)
The "endless" model in "I, zombie" of "Plants vs. Zombies" is my favou ...
- mysql补充(1)校对集utf8_unicode_ci与utf8_general_ci
创建数据库并设置编码utf-8 多语言(补充1 2) create database mydb default character set utf8 collate utf8_general_ci; ...
- Atitit. 最佳实践 QA----减少cpu占有率--cpu占用太高怎么办
Atitit. 最佳实践 QA----减少cpu占有率--cpu占用太高怎么办 跟个磁盘队列长度雅十,一到李80%走不行兰.... 1. 寻找线程too 多的.关闭... Taskman>> ...
- Android系统进程间通信(IPC)机制Binder中的Server启动过程源代码分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6629298 在前面一篇文章浅谈Android系 ...
- Android编译过程详解(三)
前面两节讲解了自定义Android编译项和创建Product产品配置文件,除了编译和定义产品相关环境变量外,还需要定义Board相关环境变量. 1. build/core/config.mk 109 ...