题目http://acm.hdu.edu.cn/showproblem.php?pid=1541

n个星星的坐标,问在某个点左边(横坐标和纵坐标不大于该点)的点的个数有多少个,输出n行,每行有一个数字,代表左下角个点数为i( i 从0开始)的点的个数。

首先将横坐标排序,这样就值需要比较纵坐标,可以采用hash的方法记录纵坐标为 i 的个数,每枚举到一个点hash加一,然后树状数组求纵坐标 不大于该点的

个数。值得注意的是树状数组是由 1 开始的,而题目可以从0开始,会超时,加一就好。

具体看代码。

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct point {
int x,y;
};
point a[];
int has[],ha[];
bool cmp(point a,point b){
if (a.x==b.x) return a.y<b.y;
return a.x<b.x;
}
void add(int x,int y){
while (x<=) {
has[x]+=y;
x+=(x&(-x));
}
}
int getsum(int x){
int ans=;
while (x>) {
ans+=has[x];
x-=(x&(-x));
}
return ans;
}
int main()
{
int n,i;
while (~scanf("%d",&n)){
memset(has,,sizeof(has));
memset(ha,,sizeof(ha));
for (i=;i<=n;i++)
scanf("%d %d",&a[i].x,&a[i].y),a[i].x++,a[i].y++;
sort(a+,a+n+,cmp);
//printf("%d\n",getsum(a[1].y));
for (i=;i<=n;i++){
ha[getsum(a[i].y)]++;
add(a[i].y,);
}
for (i=;i<n;i++) printf("%d\n",ha[i]);
}
return ;
}

hdu 1541 (基本树状数组) Stars的更多相关文章

  1. HDU 1541 STAR(树状数组)

    Stars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  2. HDU 2838 (DP+树状数组维护带权排序)

    Reference: http://blog.csdn.net/me4546/article/details/6333225 题目链接: http://acm.hdu.edu.cn/showprobl ...

  3. HDU 2689Sort it 树状数组 逆序对

    Sort it Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  4. hdu 4046 Panda 树状数组

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4046 When I wrote down this letter, you may have been ...

  5. hdu 5497 Inversion 树状数组 逆序对,单点修改

    Inversion Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5497 ...

  6. HDU 5493 Queue 树状数组

    Queue Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5493 Des ...

  7. hdu 4031(树状数组+辅助数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4031 Attack Time Limit: 5000/3000 MS (Java/Others)    ...

  8. HDU 4325 Flowers 树状数组+离散化

    Flowers Problem Description As is known to all, the blooming time and duration varies between differ ...

  9. hdu 5877 (dfs+树状数组) Weak Pair

    题目:这里 题意: 给出一个n个结点的树和一个数k,每个结点都有一个权值,问有多少对点(u,v)满足u是v的祖先结点且二者的权值之积小于等于k. 从根结点开始dfs,假设搜的的点的权值是v,我们需要的 ...

随机推荐

  1. nagiosQL访问时报错PHP message: PHP Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead

    nagiosQL安装环境: CentOS release 6.4 (Final) php-5.5.4 nagiosql_320 nginx version: nginx/1.2.3 安装一切正常,当访 ...

  2. Unity AssetBundle

    Unity AssetBundle爬坑手记 - 夜阑卧听风吹雨 时间 2014-09-15 16:55:00  博客园精华区原文  http://www.cnblogs.com/ybgame/p/39 ...

  3. python字典dict的成对运算

    dict = {'age': 18, 'name': 'jin', 'sex': 'male', }# for k,v in dict.items():# print(k,v)# v1 = dict[ ...

  4. windows 下 redis安装

    在D盘新建文件夹[redis],右键解压Redis ZIP包,把所有文件解压到redis文件夹中.(其他盘符也可以滴^_^) 文件介绍: redis-benchmark.exe         #基准 ...

  5. 重新装kafka

    Linux搭建kafka   一.安装Java 1.查看linux 的系统版本 root@aliyun:~# uname --m x86_64 2.安装java mkdir -p /usr/local ...

  6. spring 解耦

    spring之后不用在类中new一个实体,而是在类中申明接口类:当真正使用的时候是注入相应的实现类,要什么类注入申明类:那么这样就面向接口编程了:耦合度大大降低: 同时spring有面向切面编程,其实 ...

  7. vue router 懒加载实现

    在vue-cli脚手架中router文件夹中有index.js文件,里面的内容是 import Vue from 'vue'import Router from 'vue-router'import ...

  8. jq控制select值为某个时选中

    $("#selectche_type option").each(function(){//用id ,用class好像不得,不知道为何 alert(2) if($(this).va ...

  9. SpringJDBC数据库的基本使用

    SpringJDBC的基础使用部分内容 云笔记项目数据库部分采用的是Spring-MyBatis,前面学过了JDBC,SpringJDBC,Mybatis和Spring-MyBatis,有必要重新复习 ...

  10. 如何从Windows中删除Node.js

    如何从Windows中删除Node.js: 1.从卸载程序卸载程序和功能. 2.重新启动(或者您可能会从任务管理器中杀死所有与节点相关的进程). 3.寻找这些文件夹并删除它们(及其内容)(如果还有). ...