POJ 2352 Stars
题意:有一堆星星,每个星星的级别为坐标不高于它且不在它右边的星星个数,求级别为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的更多相关文章
- poj 2352 Stars 数星星 详解
题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
- POJ 2352 Stars(线段树)
题目地址:id=2352">POJ 2352 今天的周赛被虐了. . TAT..线段树太渣了..得好好补补了(尽管是从昨天才開始学的..不能算补...) 这题还是非常easy的..维护 ...
- POJ 2352 Stars(树状数组)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 30496 Accepted: 13316 Descripti ...
- 【树状数组】POJ 2352 Stars
/** * @author johnsondu * @time 2015-8-22 * @type Binary Index Tree * ignore the coordinate of y and ...
- 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(HDU 1541 Stars)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 41521 Accepted: 18100 Descripti ...
- [POJ] 2352 Stars [线段树区间求和]
Stars Description Astronomers often examine star maps where stars are represented by points on a pla ...
- (简单) POJ 2352 Stars,Treap。
Description Astronomers often examine star maps where stars are represented by points on a plane and ...
- 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 ...
随机推荐
- UML include、generalization、extend、association
1.别人的说法 转自:http://www.cnblogs.com/shinings/archive/2009/04/21/1440765.html 共性:都是从现有的用例中抽取出公共的那部分信息,作 ...
- 使用struts的模型驱动注意的问题
注意实体对象的属性命名一定要规范, 例如: private String fName; 添加时模型驱动取不到值 private String fname; 这个可以
- shell 后台执行命令
shell 后台执行命令方法: 1. nohup cmd & 后台会生成 nohup.out 文件 2.cmd >/路径/xx.log & 后台生成 xx. ...
- ubuntu下安装GTK过程
GTK的安装过程比较繁琐,以前也安装过,但没有记录下来,Google一下记录下来备用. 利用此方法成功在ubuntu12.04下安装GTK 2.24.10 1.安装gcc/g++/gdb/make 等 ...
- 原创新闻 11 个最佳 jQuery 滚动条插件
通过jQuery滚动条插件,你可以换掉千篇一律的默认浏览器滚动条,让你的网站或web项目更具特色,更有吸引力.本文收集了11款非常漂亮.实用的jQuery滚动条插件,你可以轻松将它们应用在自己的网站中 ...
- ANN中Precision-Recall权衡
如果想要得到较高的精度,则需要较长的编码. 编码长度m增长的话,则item碰撞的概率会成倍的减小,从而导致召回率下降. 为了得到较高的召回率,则需要多个哈希表. 参考http://yongyuan.n ...
- 【Unity3D】【NGUI】本地生成API文档
原地址:http://blog.csdn.net/u012091672/article/details/17438135 NGUI讨论群:333417608 1.安装Doxygen(http://ww ...
- jquery 请求jsp传递json数据的方法
$(function() { $("a[name=hrefID]").click(function() { var id = $(this).attr("id" ...
- Tomcat多次部署
http://blog.csdn.net/knityster/article/details/6300804
- 在linux下,查看一个运行中的程序, 占用了多少内存
1. 在linux下,查看一个运行中的程序, 占用了多少内存, 一般的命令有 (1). ps aux: 其中 VSZ(或VSS)列 表示,程序占用了多少虚拟内存. RSS列 表示, 程序占用了多少物 ...