HDU - 1541

思路:二维偏序,一维排序,一维树状数组查询即可。

#include<bits/stdc++.h>
using namespace std;
#define maxn 33333
int ans[maxn],n,sum[maxn];
int lowbit(int x)
{
return x&(-x);
}
struct node
{
int x,y;
bool operator < (const node &b)const
{
if(x==b.x)return y<b.y;
return x<b.x;
}
} a[maxn];
void add(int x,int d)
{
while(x<=32001)
{
sum[x]+=d;
x+=lowbit(x);
}
}
int getsum(int x)
{
int ret=0;
while(x>0)
{
ret+=sum[x];
x-=lowbit(x);
}
return ret;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(sum,0,sizeof(sum));
memset(ans,0,sizeof(ans));
for(int i=1; i<=n; i++)
scanf("%d%d",&a[i].x,&a[i].y);
sort(a+1,a+1+n);
for(int i=1; i<=n; i++)
{
ans[getsum(a[i].y+1)]++;
add(a[i].y+1,1);
}
for(int i=0; i<n; i++)printf("%d\n",ans[i]);
}
return 0;
}

  

Stars HDU - 1541的更多相关文章

  1. POJ 2352 Stars(HDU 1541 Stars)

    Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 41521   Accepted: 18100 Descripti ...

  2. hdu 1541 Stars

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 思路:要求求出不同等级的星星的个数,开始怎么也想不到用树状数组,看完某些大神的博客之后才用树状数 ...

  3. POJ 2352 &amp;&amp; HDU 1541 Stars (树状数组)

    一開始想,总感觉是DP,但是最后什么都没想到.还暴力的交了一发. 然后開始写线段树,结果超时.感觉自己线段树的写法有问题.改天再写.先把树状数组的写法贴出来吧. ~~~~~~~~~~~~~~~~~~~ ...

  4. hdu 1541 (基本树状数组) Stars

    题目http://acm.hdu.edu.cn/showproblem.php?pid=1541 n个星星的坐标,问在某个点左边(横坐标和纵坐标不大于该点)的点的个数有多少个,输出n行,每行有一个数字 ...

  5. HDU - 1541 Stars 【树状数组】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1541 题意 求每个等级的星星有多少个 当前这个星星的左下角 有多少个 星星 它的等级就是多少 和它同一 ...

  6. hdu 1541 Stars 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 题目意思:有 N 颗星星,每颗星星都有各自的等级.给出每颗星星的坐标(x, y),它的等级由所有 ...

  7. hdu 1541/poj 2352:Stars(树状数组,经典题)

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

  8. HDU 1541 Stars (树状数组)

    Problem Description Astronomers often examine star maps where stars are represented by points on a p ...

  9. HDU 1541 Stars (线段树)

     Problem Description Astronomers often examine star maps where stars are represented by points on ...

随机推荐

  1. Apache Beam实战指南 | 手把手教你玩转大数据存储HdfsIO

    https://mp.weixin.qq.com/s?__biz=MzU1NDA4NjU2MA==&mid=2247494843&idx=2&sn=0dd20caec76e25 ...

  2. go interface接口

    一:接口概要 接口是一种重要的类型,他是一组确定的方法集合. 一个接口变量可以存储任何实现了接口方法的具体值.一个重要的例子就是io.Reader和io.Writer type Reader inte ...

  3. centos中编译安装nginx+mysql +php(未完)

    参考地址:http://www.cnblogs.com/htian/p/5728599.html 去官网找到PCRE,并下载http://www.pcre.org/wget ftp://ftp.csx ...

  4. idea中的一些快捷键,未完待续......

    1.快速查看注释的渲染效果 在keymap中查找“Quick Documentation”并设置自己喜欢的快捷键即可 2.全局搜索 在keymap中查找“Replace in Path”并设置自己喜欢 ...

  5. go 数组 切片 字典 结构体

    数组 ##数组的定义与赋值: 1. var num [3]int num = [3]int{1,2,3} 2. var num [3]int = [3]int {1,2,3} 3. num := [3 ...

  6. VUE-Windows系统下搭建vue环境

    一.安装node.js(https://nodejs.org/en/) 下载完毕后,可以安装node,建议不要安装在系统盘(如C:).注意记下路径..   此处默认安装这4项即可,点击Next按钮. ...

  7. 四十九、进程间通信——System V IPC 之消息队列

    49.1 System V IPC 介绍 49.1.1 System V IPC 概述 UNIX 系统存在信号.管道和命名管道等基本进程间通讯机制 System V 引入了三种高级进程间通信机制 消息 ...

  8. 学习WPF

    http://www.cnblogs.com/prism/archive/2010/07/21/1781855.html 如何在WPF中画三角,以及把按钮设置成颜色渐变的样式:

  9. 编译Android ROM环境搭建

    环境搭建 1 安装ubuntu 推荐12.04或13.10 2 安装jdk7和一些所需要的包安装jdk7$ sudo apt-get update$ sudo apt-get install open ...

  10. Spring Cloud 2-Hystrix 断路容错保护(四)

    Spring Cloud  Hystrix  1.RestTemplate 容错 pom.xml application.yml application.java HelloService.java ...