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 ...
随机推荐
- Unity3d 如何找到游戏对象并改变其颜色
//游戏对象 private var obj:GameObject; //渲染器 private var render:Renderer; //贴图 private var texture:Textu ...
- UIImageView加抖动效果(转)
CGAffineTransform moveRight = CGAffineTransformTranslate(CGAffineTransformIdentity, 20, 0); CGAffine ...
- jq 7种实例化
$(html) ->$(array) $(html,{}||$(...)) $(#id) $(expr,$(...)) $(expr,context) $(dom) $(function(){} ...
- EF当实体模型与数据库的架构不同时要删除数据库时的报错问题
当使用的EF的时候,我们都知道EF当实体模型与数据库的架构不同时要删除数据库,这是会把错: 无法创建与 'master' 数据库之间的连接,这是因为已打开原始数据库连接,并且已从连接字符串中删除凭据. ...
- Jplayer(转)
Jplayer必须要加载 1.样式 jplayer.blue.monday.css 2.jq jquery.1.6.2.min.js 当前最新版本为1.6.2 3.jplayer的js jquery ...
- CQRS学习——一个例子(其六)
[先上链接:http://pan.baidu.com/s/1o62AHbc ] 多图杀猫 先用一组图看看实现的功能: 添加一个功能 假定现在要添加一个书本录入的功能,那么执行如下的操作: 1.添加Co ...
- State Management
Samza的task可以把数据进行本地存储,并且对这些数据进行丰富的查询. 比较SQL中的select ... where...并不需要保存状态.但是aggregation和join就需要存储ro ...
- python url编码
1.quote:使用适合URL内容的转义序列替换String中的特殊字符. 2.quote_plus:调用quote并使用“+”替换所有空格 3.unquote:使用转义字符的单字符对应物替换'%xx ...
- C语言:将16进制字符串转化为int类型值
将16进制字符串值转换为 int 整型值 此例中用 "1de" 作为测试字符串,实现代码如下: #include <stdio.h> #include <stdl ...
- Android 图片旋转(使用Matrix.setRotate方法)
imageView2 = (ImageView) findViewById(R.id.img2); Bitmap bitmap = BitmapFactory.decodeResource(getRe ...