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加 ...
随机推荐
- HDU 3351 Seinfeld(括号匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3351 解题报告:输入一个只有'{'跟'}'的字符串,有两种操作,一种是把'{'变成'}',另一种是'} ...
- Codeforces 259 B - Little Pony and Sort by Shift
题目链接:http://codeforces.com/contest/454/problem/B 解题报告:太渣了,这个模拟题最后跑大数据的时候挂了,最后还花了很久才过,用的最笨的方法,直接模拟,代码 ...
- HTTP协议概念篇
1.概念 协议是指计算机通信网络中两台计算机之间进行通信所必须共同遵守的规定或规则,超文本传输协议(HTTP)是一种通信协议,它允许将超文本标记语言(HTML)文档从Web服务器传送到客户端的浏览器. ...
- 2016-03-12 Leanning Plan
1,Python 2,Java 3,Html+Css 4,PHP 5,Crawl 6,WetChat Platform
- httpclient+Jsoup总结
Jsoup.parse解析HTML字符串,如Jsoup.parse("<html><head><title>Firstparse</title> ...
- 4.6---找二叉树中序后继(CC150)
因为,没有重复值,所以只需要做一个标记就OK了. public class Successor { static boolean flag = false; static int result = 0 ...
- C# XML和实体类之间相互转换(序列化和反序列化)
我们需要在XML与实体类,DataTable,List之间进行转换,下面是XmlUtil类,该类来自网络并稍加修改. using System; using System.Collections.Ge ...
- bootstrap按钮
按钮 基类 -btn 样式 btn-default(默认) btn-link(链接) 大小 btn-*[lg,sm,xs] 状态 active disabled <!DOCTYPE HTML&g ...
- Dom终
l创建DOM元素 •createElement(标签名) 创建一个节点 •appendChild(节点) 追加一个节点 –例子:为ul插入li <!DOCTYPE html PUBLIC & ...
- Java读取mat文件
概述 使用ujmp中的jmatio模块读取.mat文件到java程序中. 其实,ujmp主要是在模块core中实现了矩阵运算,其余模块都是复用了已有的开源库.模块jmatio是复用了已有的JMatIo ...