hdu 1541 Stars 统计<=x的数有几个
Stars
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 15951 Accepted Submission(s): 5945

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.
注意:航电里面的数据范围少了一个0,0<= x,y <=320000
#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;
int b[],vis[];
int lowbit(int x)//x的二进制表达中,从右往左第一个1所在的位置表示的数,返回的是这个数的十进制数
{
return x&(-x);
}
void add(int x)
{
while(x<=)
{
b[x]++;
x=x+lowbit(x);
}
}
int getnum(int x)
{
int cnt=;
while(x>)
{
cnt=cnt+b[x];
x=x-lowbit(x);
}
return cnt;
}
int main()
{
int t,x,y;
while(~scanf("%d",&t))
{
memset(vis,,sizeof(vis));
memset(b,,sizeof(b));
for(int i=;i<t;i++)
{
scanf("%d%d",&x,&y);
vis[getnum(x+)]++;//统计<=x的数有几个
add(x+);
}
for(int i=;i<t;i++)
printf("%d\n",vis[i]);
}
}
hdu 1541 Stars 统计<=x的数有几个的更多相关文章
- hdu 1541 Stars 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 题目意思:有 N 颗星星,每颗星星都有各自的等级.给出每颗星星的坐标(x, y),它的等级由所有 ...
- HDU 1541 Stars (树状数组)
Problem Description Astronomers often examine star maps where stars are represented by points on a p ...
- hdu 1541 Stars
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 思路:要求求出不同等级的星星的个数,开始怎么也想不到用树状数组,看完某些大神的博客之后才用树状数 ...
- POJ 2352 && HDU 1541 Stars (树状数组)
一開始想,总感觉是DP,但是最后什么都没想到.还暴力的交了一发. 然后開始写线段树,结果超时.感觉自己线段树的写法有问题.改天再写.先把树状数组的写法贴出来吧. ~~~~~~~~~~~~~~~~~~~ ...
- HDU - 1541 Stars 【树状数组】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1541 题意 求每个等级的星星有多少个 当前这个星星的左下角 有多少个 星星 它的等级就是多少 和它同一 ...
- 题解报告:hdu 1541 Stars(经典BIT)
Problem Description Astronomers often examine star maps where stars are represented by points on a p ...
- POJ 2352 Stars(HDU 1541 Stars)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 41521 Accepted: 18100 Descripti ...
- HDU 1541 Stars (线段树)
Problem Description Astronomers often examine star maps where stars are represented by points on ...
- hdu 1541 Stars(线段树单点更新,区间查询)
题意:求坐标0到x间的点的个数 思路:线段树,主要是转化,根据题意的输入顺序,保证了等级的升序,可以直接求出和即当前等级的点的个数,然后在把这个点加入即可. 注意:线段树下标从1开始,所以把所有的x加 ...
随机推荐
- iOS 开发之使用链式编程思想实现简单的计算器
链式编程思想是将多个操作(多行代码)通过点号(.)链接在一起成为一句代码,使代码可读性好.例如 a(1).b(2).c(3). 链式编程思想最为关键的是,方法的返回值是block,block必须返回对 ...
- 腾讯云Windows Server下nodejs websocket ssl配置
1.从腾讯云申请SSL证书,下载解压,得到如下文件: 2.nodejs代码: // wss.js const fs = require('fs'); // 一些配置信息 const cfg = { p ...
- Linux - Windows下的Linux工具
1. putty, 2. winscp(可下载文件) 3. SecureCRT
- acm数论之旅(转载) -- 快速幂
0和1都不是素数,也不是合数. a的b次方怎么求 pow(a, b)是数学头文件math.h里面有的函数 可是它返回值是double类型,数据有精度误差 那就自己写for循环咯 LL pow(LL a ...
- vs2017 vs2019配置sqlite3连接引擎(驱动)指南(二)vs2019续集
在写完上一篇博客后,一觉醒来,又又又又不行了,介绍一个终极大招,如果你的fuck vs又提示无法打开sqlite3.h的问题 环境win10 vs2019 debug x86 实在没心情写文字了,直 ...
- C++11特性中基于范围的for循环
本文摘录柳神笔记: 除了像C语⾔的for语句 for (i = 0; i < arr.size(); i++) 这样,C++11标准还为C++添加了⼀种新的 for 循环⽅ 式,叫做基于范围 ...
- onclick="this.src=this.src+'?'"是什么意思?
onclick="this.src=this.src+'?'" 这是表示当前图片链接 在当前链接值的基础上添加了一个问号 譬如当前src="check.aspx" ...
- 基于通用二进制方式安装MySQL-5.7.24(比源码安装MySQL快许多)及破密码
确保系统中有依赖的libaio软件 yum -y install libaio 使用wget命令下载mysql-5.7.24软件包 wget http://mirrors.sohu.com/mysql ...
- CSS三列自适应布局(两边宽度固定,中间自适应)
https://blog.csdn.net/cinderella_hou/article/details/52156333 https://blog.csdn.net/wangchengiii/art ...
- springMVC读取本地图片显示到前端页面
@RequestMapping("/getImage") @ResponseBody public void getImagesId(HttpServletResponse rp) ...