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加 ...
随机推荐
- POJ2104 —— K-th number
1.题目大意:区间第k小,什么修改没有... 2.分析:这个是可持久化线段树,也是主席树,解释一下,n个线段树是怎么存下的,就是每一颗线段树和前一个有logn个点不一样 然后我们只需要一个线段树开lo ...
- 写给喜欢用Block的朋友(ios Block)
作者:fengsh998原文地址:http://blog.csdn.net/fengsh998/article/details/38090205转载请注明出处如果觉得文章对你有所帮助,请通过留言或关注 ...
- IC/RFID/NFC 关系与区别
IC卡 (Integrated Circuit Card,集成电路卡) 有些国家和地区也称智能卡(smart card).智慧卡(intelligent card).微电路卡(microcircuit ...
- POJ 1995 快速幂模板
http://poj.org/problem?id=1995 简单的快速幂问题 要注意num每次加过以后也要取余,否则会出问题 #include<iostream> #include< ...
- 解决 QtCreator 3.5(4.0)无法输入中文的问题
解决 QtCreator 3.5.1无法输入中文的问题 [TOC] 环境是ubuntu 15.10 ubuntu软件源中下载安装的fctix-libs-qt5现在没有用,版本太旧了. 自己下载fcti ...
- 5. apktool 给XX手机卫士加广告页
一. 编写广告页 写一个广告页面,并调用其他页面的demo (1) 设计界面如下 (2) 编写代码如下 public class SplashActivity extends Activity { ...
- Python分割list
对于一个很大的列表,例如有超过一万个元素的列表,假如需要对列表中的每一个元素都进行一个复杂且耗时的计算,用单线程处理起来会很慢,这时有必要利用多线程进行处理,处理之前首先需要对大的列表进行分割,分割成 ...
- 流程图制作在云上 https://www.processon.com/
流程图制作在云上 : https://www.processon.com/
- 如何用 Robotframework 来编写优秀的测试用例
介绍 这篇文档将会是一篇在「高层面」的怎么用 Robotframework 来编写优秀测试用例的原则.至于如何使用 Robotframework 来与您的待测试系统相作用这样的细节讨论是不包含在这篇文 ...
- 解读Unity中的CG编写Shader系列二
转自 http://www.itnose.net/detail/6095974.html 上一篇文章的例子中我们可以看到顶点着色器的输出参数可以说是直接作为了片段着色器的形参传递过来,那么不由得一个问 ...