首页 技术 正文
技术 2022年11月12日
0 收藏 462 点赞 2,209 浏览 938 个字

题目链接: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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,488
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,489
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,290