hdu1541 Stars
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.
are listed in ascending order of Y coordinate. Stars with equal Y coordinates are listed in ascending order of X coordinate.
1 1
5 1
7 1
3 3
5 5
2
1
10
这题是简单的线段树应用,好像也可以用树状数组做,以后学了再做一次(笑)。因为题目中的坐标是先按纵坐标大小,再按横坐标大小排列的,所以一个左边的值就是比它横坐标小的值再加上它下面的坐标。可以用线段树维护区间的小于等于区间右端点的横坐标的个数,这里查询和更新放在了一起,从根节点到叶子节点是查询,再从叶子节点递归上来是询问。
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define maxn 32005
int num,vis[15005];
struct node{
int l,r,num;
}b[8*maxn];
void build(int l,int r,int i)
{
int mid;
b[i].l=l;b[i].r=r;b[i].num=0;
if(l==r)return;
mid=(l+r)/2;
build(l,mid,i*2);
build(mid+1,r,i*2+1);
}
void update(int id,int i)
{
int mid;
if(b[i].l==b[i].r){
num+=b[i].num;
b[i].num++;return;
}
if(b[i*2].r>=id){
update(id,i*2);
}
else{
num+=b[i*2].num;
update(id,i*2+1);
}
b[i].num=b[i*2].num+b[i*2+1].num;
}
int main()
{
int n,m,i,j,c,d;
while(scanf("%d",&n)!=EOF)
{
memset(vis,0,sizeof(vis));
build(0,32005,1);
for(i=1;i<=n;i++){
scanf("%d%d",&c,&d);
num=0;
update(c,1);
vis[num]++;
}
for(i=0;i<=n-1;i++){
printf("%d\n",vis[i]);
}
}
return 0;
}
hdu1541 Stars的更多相关文章
- HDU-1541 Stars 树状数组
题目链接:https://cn.vjudge.net/problem/HDU-1541 题意 天上有许多星星 现给天空一个平面坐标轴,统计每个星星的level, level是指某一颗星星的左下角(x& ...
- hdu1541 Stars 树状数组
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 题目大意就是统计其左上位置的星星的个数 由于y已经按升序排列,因此只用按照x坐标生成一维树状数组 ...
- 树状数组入门 hdu1541 Stars
树状数组 树状数组(Binary Indexed Tree(B.I.T), Fenwick Tree)是一个查询和修改复杂度都为log(n)的数据结构.主要用于查询任意两位之间的所有元素之和,但是每次 ...
- [学习笔记]CDQ分治和整体二分
序言 \(CDQ\) 分治和整体二分都是基于分治的思想,把复杂的问题拆分成许多可以简单求的解子问题.但是这两种算法必须离线处理,不能解决一些强制在线的题目.不过如果题目允许离线的话,这两种算法能把在线 ...
- poj 2352 Stars 数星星 详解
题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
- HDU1541 树状数组
Stars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- POJ 2352 Stars(树状数组)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 30496 Accepted: 13316 Descripti ...
- 【POJ-2482】Stars in your window 线段树 + 扫描线
Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11706 Accepted: ...
- Java基础之在窗口中绘图——填充星型(StarApplet 2 filled stars)
Applet程序. import javax.swing.*; import java.awt.*; import java.awt.geom.GeneralPath; @SuppressWarnin ...
随机推荐
- python学习笔记 | 顺序表的常规操作
''' @author: 人人都爱小雀斑 @time: 2020/3/11 8:46 @desc: 顺序表的相关操作 ''' class SequenceList: def __init__(self ...
- 【ORA】ORA-32004: 问题分析和解决
今天做一个特殊的实验,需要重启数据库 数据库关闭没有问题 SQL> shutdown immediate; Database closed. Database dismounted. ORACL ...
- 基础练习(上) - 蓝桥杯(Python实现)
闰年判断: 题目: 资源限制 时间限制:1.0s 内存限制:256.0MB 问题描述 给定一个年份,判断这一年是不是闰年. 当以下情况之一满足时,这一年是闰年: 1. 年份是4的倍数而不是100的倍数 ...
- 利用iptables防火墙保护web服务器
实例:利用iptables防火墙保护web服务器 防火墙--->路由器-->交换机-->pc机 配置之前,清空下已有的规则,放在规则冲突不生效 工作中,先放行端口写完规则,再DROP ...
- migo的BAPI示例BAPI_GOODSMVT_CREATE
1 *&---------------------------------------------------------------------* 2 *& Report Z_BAP ...
- [Usaco2016 Dec]Moocast
原题链接https://www.lydsy.com/JudgeOnline/problem.php?id=4749 可以对于每个点\(i\),往跟\(i\)距离小于等于\(p[i]\)的点\(j\)都 ...
- linux登陆欢迎信息及命令提示符修改
登录信息修改 登陆信息显示数据 : /etc/issue and /etc/motd 登陆终端机的时候,会有几行提示的字符串,这些设置在/etc/issue里面可以修改,提示内容在/etc/motd中 ...
- Mybatis参数预编译
Mybatis参数预编译 一.数据库预编译介绍 1.数据库SQL语句编译特性: 数据库接受到sql语句之后,需要词法和语义解析,优化sql语句,制定执行计划.这需要花费一些时间.但是很多情况,我们的一 ...
- Mysql四种通信协议(linux下本地连接的都是socket 其他都是tcp)
Mysql通信协议 - 张冲andy - 博客园 https://www.cnblogs.com/andy6/p/6204579.html
- functools.singledispatchmethod(Python 3.8) | 码农网 https://www.codercto.com/a/83245.html
functools.singledispatchmethod(Python 3.8) | 码农网 https://www.codercto.com/a/83245.html