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加 ...
随机推荐
- BFS(广度优先搜索遍历保存全局状态,华容道翻版做法)--08--DFS--蓝桥杯青蛙跳杯子
题目描述 X星球的流行宠物是青蛙,一般有两种颜色:白色和黑色. X星球的居民喜欢把它们放在一排茶杯里,这样可以观察它们跳来跳去. 如下图,有一排杯子,左边的一个是空着的,右边的杯子,每个里边有一只青蛙 ...
- STM32内部时钟树
1.外部晶振是干什么用的? 2.内部晶振是干什么用的? 3.外部晶振频率的大小能影响什么?
- cookie,session,localStorage和sessionStorage
cookies:存储于浏览器端的数据.可以设置 cookies 的Max-Age或者Expires到期时间,如果不设置时间,则在浏览器关闭窗口的时候会消失. session:存储于服务器端的数据.se ...
- XCOJ 1008: 级数求和
1008: 级数求和 题目描述 已知:Sn= 1+1/2+1/3+…+1/n.显然对于任意一个整数K,当n足够大的时候,Sn大于K.现给出一个整数K(1<=k<=15),要求计算出一个最小 ...
- redis使用技巧小结
一.Redis 密码设置和查看密码redis没有实现访问控制这个功能,但是它提供了一个轻量级的认证方式,可以编辑redis.conf配置来启用认证.1.初始化Redis密码:在配置文件中有个参数:re ...
- Priority Queue(优先队列)
今天早上起来完成了一个完整的基于二叉堆实现的优先队列,其中包含最小优先和最大优先队列. 上篇说了优先队列的特性,通过建堆和堆排序操作,我们就已经看到了这种数据结构中的数据具有某种优先级别,要么非根节点 ...
- 扒网站工具 HTTrack Website Copier
下载地址:http://www.pc6.com/softview/SoftView_30936.html 作者:匿名用户 链接:https://www.zhihu.com/question/34188 ...
- Go文档:go命令
目录 go go bug--启动bug报告 go build--编译包及其依赖包 go clean--删除对象文件和缓存文件 go doc--查看包或符号的文档 go env--打印环境变量 go f ...
- missing required architecture x86_64 in file
ios错误ignoring file xxx missing required architecture x86_64 in file 错误ignoring file xxx missing re ...
- ElementUI el-message 提示信息的用法
引入message Element 注册了一个$message方法用于调用,Message 可以接收一个字符串或一个 VNode 作为参数,它会被显示为正文内容. Element 为 Vue.prot ...