hdu 1541 Stars
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541
思路:要求求出不同等级的星星的个数,开始怎么也想不到用树状数组,看完某些大神的博客之后才用树状数组写的,搞了好久才懂得数组的更新过程
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<vector>
#include<queue>
#include<iterator>
#include<vector>
#include<set>
#define dinf 0x3f3f3f3f
typedef long long ll;
const int Max=(<<)+;
using namespace std; #define SIZE 1000005 int c[SIZE],level[SIZE],n; int Lowbit(int x)
{
return x&(-x);
} int Sum(int x)
{
int sum=;
while(x>)
{
sum+=c[x];
x-=Lowbit(x);
}
return sum;
} void Update(int i,int x)
{
while(i<=SIZE)//要把所有的与i相关的c数组中的值全部更新,不然会出错
{
c[i]+=x;
i+=Lowbit(i);
}
} int main()
{
while(~scanf("%d",&n))
{
memset(level,,sizeof(level));
memset(c,,sizeof(c));
int x,y;
for(int i=;i<n;i++)
{
scanf("%d %d",&x,&y);
level[Sum(++x)]++;
Update(x,);
/*
for(int j=0;j<10;j++)
printf("%d ",c[j]);
printf("\n");
for(int j=0;j<10;j++)
printf("%d ",level[j]);
printf("\n");
*/
}
for(int i=;i<n;i++)
printf("%d\n",level[i]);
}
return ;
}
附上样例中数组的更新过程,上面一行是c[i],下面是level[i]
hdu 1541 Stars的更多相关文章
- POJ 2352 && HDU 1541 Stars (树状数组)
一開始想,总感觉是DP,但是最后什么都没想到.还暴力的交了一发. 然后開始写线段树,结果超时.感觉自己线段树的写法有问题.改天再写.先把树状数组的写法贴出来吧. ~~~~~~~~~~~~~~~~~~~ ...
- HDU - 1541 Stars 【树状数组】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1541 题意 求每个等级的星星有多少个 当前这个星星的左下角 有多少个 星星 它的等级就是多少 和它同一 ...
- hdu 1541 Stars 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 题目意思:有 N 颗星星,每颗星星都有各自的等级.给出每颗星星的坐标(x, y),它的等级由所有 ...
- 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 a p ...
- HDU 1541 Stars (线段树)
Problem Description Astronomers often examine star maps where stars are represented by points on ...
- 题解报告:hdu 1541 Stars(经典BIT)
Problem Description Astronomers often examine star maps where stars are represented by points on a p ...
- hdu 1541 Stars 统计<=x的数有几个
Stars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- hdu 1541 Stars(线段树单点更新,区间查询)
题意:求坐标0到x间的点的个数 思路:线段树,主要是转化,根据题意的输入顺序,保证了等级的升序,可以直接求出和即当前等级的点的个数,然后在把这个点加入即可. 注意:线段树下标从1开始,所以把所有的x加 ...
随机推荐
- spring 控制事务
<!-- 对数据源进行事务管理 --> <bean id="transactionManager" class="org. ...
- [BZOJ1503][NOI2004]郁闷的出纳员
[BZOJ1503][NOI2004]郁闷的出纳员 试题描述 OIER公司是一家大型专业化软件公司,有着数以万计的员工.作为一名出纳员,我的任务之一便是统计每位员工的工资.这本来是一份不错的工作,但是 ...
- Laravel 5.1 文档攻略 —— Eloquent: 读取器和修饰器
date_range 8月前 tag_faces Woody remove_red_eye 1483 chat0 简介 这一章其实很简单,Model的属性不是和数据表的字段一一对应吗? 那么在存储和呈 ...
- MySQL分配角色权限
1.创建新用户 通过root用户登录之后创建 >> grant all privileges on *.* to testuser@localhost identified by &quo ...
- hadoop小试
standard mode(标准模式) 下载 wget http://mirror.bit.edu.cn/apache/hadoop/common/stable/hadoop-2.7.2.tar.gz ...
- Java BigDecimal使用
//除法:精确到后4位BigDecimal a = new BigDecimal(1213); BigDecimal b = new BigDecimal(10302); BigDecimal rat ...
- android 和iOS的view上的区别
android上的view的类叫View, 以下是它的class overview, This class represents the basic building block for user i ...
- MySQL Plugin 'InnoDB' init function returned error
. . 在MySQL的配置文件中,设定default-table-type=InnoDB,发现MySQL无法正常的启动,错误日志中给出了如下的信息: 150210 18:11:19 mysqld_sa ...
- openal-1.13 静态编译(mingw32)
1.CMakeLists.txt SET(LIBTYPE SHARED) 改成 SET(LIBTYPE STATIC) 2.include/al/al.h 删除 dllexport 3.include ...
- Effective C++ -----条款49:了解new-handler 的行为
set_new_handler允许客户指定一个函数,在内存分配无法获得满足时被调用. Nothorw new 是一个颇为局限的工具,因为它只适用于内存分配:后继的构造函数调用还是可能抛出异常.