POJ2352:Stars——题解
http://poj.org/problem?id=2352
Astronomers晚上仰望星空,看到了很多星星。回到办公桌,Astronomers将这些星星画到二维坐标系,每个星星的坐标都是整数。例如5个星星,坐标分别为(1,1), (5,1), (7,1), (3,3), (5,5):
Astronomers想对这些星星定等级,规则是这样的:每个星星左下角有几个星星,它就算几级(包含左边和下面)。上面的例子,第1颗星星的等级为0,等2颗星星的等级为1,第3颗星星的等级为2,第4颗星星的等级为1,第5颗星星的等级为3。
所以,等级为0的星星有1颗,等级为1的星星有2颗,等级为2的星星有1颗,等级为3的星星有1颗,等级为4的星星为0颗。
给定N个星星坐标,没有两个星星坐标在一起,问你等级为0~N-1的星星数量是多少。
首先对于星星坐标按照先y后x排序,然后按照x的坐标加星星个数统计即可。
****注意星星坐标可能从0开始,所以最开始我们对坐标+1。
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
inline ll read(){
int X=,w=; char ch=;
while(ch<''||ch>''){w|=ch=='-';ch=getchar();}
while(ch>=''&&ch<='')X=(X<<)+(X<<)+(ch^),ch=getchar();
return w?-X:X;
}
const int N=;
struct node{
int x;
int y;
}star[];
bool cmp(node a,node b){
if(a.y<b.y)return ;
if(a.y>b.y)return ;
if(a.x<b.x)return ;
return ;
}
int n,m;
ll tree[N];
ll ans[];
inline int lowbit(int t){return t&(-t);}
void add(int x,int y){
for(int i=x;i<=N;i+=lowbit(i))tree[i]+=y;
return;
}
ll query(int x){
ll res=;
for(int i=x;i>;i-=lowbit(i))res+=tree[i];
return res;
}
int main(){
n=read();
for(int i=;i<=n;i++){
star[i].x=read()+;
star[i].y=read()+;
}
sort(star+,star+n+,cmp);
for(int i=;i<=n;i++){
int t=query(star[i].x);
ans[t]++;
add(star[i].x,);
}
for(int i=;i<n;i++){
printf("%lld\n",ans[i]);
}
return ;
}
POJ2352:Stars——题解的更多相关文章
- POJ-2352 Stars 树状数组
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39186 Accepted: 17027 Description A ...
- poj2352 Stars【树状数组】
Astronomers often examine star maps where stars are represented by points on a plane and each star h ...
- POJ2352 Stars 树状数组
emm,ssy说可以直接CDQ分治...%%%但是注意到y是有序的,所以可以直接求一下前缀和就行了. 题干: Astronomers often examine star maps where sta ...
- POJ2352 Stars [树状数组模板]
题意:输入一n颗星星的x,y坐标,给定判断level的标准,即某颗星星左下边(不高于它,不超过他,相当于以他为基准的第三象限)星星的数目为level, 输出level从0到n的星星个数. //poj2 ...
- POJ2352 Stars (静态二叉检索树)
https://vjudge.net/problem/POJ-2352 分析: 由于是按照y坐标的升序,y坐标向等的按x的升序的顺序给出星星.那么某个星星的等级数就是在他前面x坐标小于等于他的x坐标的 ...
- poj2352 Stars
http://poj.org/problem?id=2352 #include <cstdio> #include <cstring> #define maxn 400000 ...
- 【二维偏序】【树状数组】【权值分块】【分块】poj2352 Stars
经典问题:二维偏序.给定平面中的n个点,求每个点左下方的点的个数. 因为 所有点已经以y为第一关键字,x为第二关键字排好序,所以我们按读入顺序处理,仅仅需要计算x坐标小于<=某个点的点有多少个就 ...
- [POJ2352] Stars(树状数组)
传送门 先按照下标x排序,然后依次把y加入树状数组,边加入边统计即可. 注意下标re从零开始,需+1s ——代码 # include <iostream> # include <cs ...
- 树状数组 poj2352 Stars
2019-05-20 22:52:07 加油,坚持,加油,坚持 !!! #include<iostream> #include<cstdio> #include<cstr ...
随机推荐
- 阿里otter使用问题汇总
最近在使用otter做为和表从库.(100个分表太难查询了) user_00,user_01...user_99 => user_all 1.问题DDL语句不能执行(exception:setl ...
- libevent学习三(Getting an event_base)
1.一个event_base持有了一系列的事件,并监控和决定哪些事件需要激活, 2.每一个event_base背后都有一个支持其工作的方法(诸如select,poll,epoll,kquene...) ...
- c++ singleton
http://www.yolinux.com/TUTORIALS/C++Singleton.html
- Ubuntu16.04比较好的一系列软件安装介绍
https://blog.csdn.net/Gerald_Jones/article/details/80784976
- Selenium自动化测试基础
如有任何学习问题,可以添加作者微信:lockingfree 目录 Selenium自动化测试基础 Selenium自动化测试第一天(上) Selenium自动化测试第一天(下) Selenium自动化 ...
- 【springmvc+mybatis项目实战】杰信商贸-2.数据库配置
首先我们来了解项目的架构 我们分别使用了MySql和Oracle数据库,即是异构数据库.我们做到一个平台支持多个数据库.数据库建模我们使用Sybase公司的PowerDesigner(以后简称PD), ...
- [Clr via C#读书笔记]Cp14字符字符串和文本处理
Cp14字符字符串和文本处理 字符 System.Char结构,2个字节的Unicode,提供了大量的静态方法:可以直接强制转换成数值: 字符串 使用最频繁的类型:不可变:引用类型,在堆上分配,但是使 ...
- 词嵌入向量WordEmbedding
词嵌入向量WordEmbedding的原理和生成方法 WordEmbedding 词嵌入向量(WordEmbedding)是NLP里面一个重要的概念,我们可以利用WordEmbedding将一个单 ...
- LeetCode - 231. Power of Two - 判断一个数是否2的n次幂 - 位运算应用实例 - ( C++ )
1.题目:原题链接 Given an integer, write a function to determine if it is a power of two. 给定一个整数,判断该整数是否是2的 ...
- Python3 Tkinter-Menu
1.创建 from tkinter import * root=Tk() menubar=Menu(root) def hello(): print('Hello Menu!') for item i ...