树状数组POJ2352星星
2024-08-27 04:50:49
http://poj.org/problem?id=2352
这道题的题意对于住学者应该比较难理解,但是如果弄明白他的意思的话,你就会发现这就是赤裸裸的树状数组,哎,欺负我不懂是吧,当时读题读啦好久,好啦,下面说一下他的意思吧。。
由于题目已经说明y的坐标是递增顺序,所以直接考虑x的坐标就可以啦。每次当有x输入时,都求出sum(x+1)的值(注意呦,在树状数组中,可是从1开始的,而题目中的输入是包含0的),并把result[sum(x+1)]++;再更新一下,就好啦啦啦啦。
还是要注意一点,用c++提交超时,还是用c吧!!!!!!!!!!!!!!!!
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
const int N=;
using namespace std;
int c[N+];
int n;
int lowbit(int i){
return i&(-i);
}
void add(int i,int x)
{
while(i<=N){
c[i]+=x;
i+=lowbit(i);
}
}
int sum(int i)
{
int s=;
while(i>){
s+=c[i];
i-=lowbit(i);
}
return s;
}
int main(){
int a,b;
int result[N];
scanf("%d",&n);
//memset(result,0,sizeof(result));
//memset(c,0,sizeof(c));
for(int i=;i<n;i++){
scanf("%d%d",&a,&b);
int temp=sum(a+);
result[temp]++;
add(a+,);
}
for(int i=;i<n;i++){
cout<<result[i]<<endl;
}
}
最新文章
- Windows Azure Storage (17) Azure Storage读取访问地域冗余(Read Access – Geo Redundant Storage, RA-GRS)
- 配置samba
- 微软“One Windows”的梦想已经破灭了吗?
- Oracle【IT实验室】数据库备份与恢复之六:LogMiner
- (转)MySQL提示“too many connections”的解决办法
- js判断字符是否包含字母汉字
- instancetype、id、NSObject的联系和区别
- spring mvc中的@PathVariable(转)
- 破解密码那些事儿(Hacking Secret Ciphers with Python)
- golang之interface(接口)与 reflect 机制
- [原创] 利用前端+php批量生成html文件,传入新文本,输出新的html文件
- Linux已经全然统治了这个世界:反对开源社区愚不可及
- Windows上最大传输单元MTU值的查看和设置
- JS查找字符串中出现次数最多的字符
- Node.js目录
- docker环境下solrcloud+zookeeper集群部署教程
- 判断String类型字符串是否为空的方法
- vs各种版本
- 【转载】 强化学习(十)Double DQN (DDQN)
- 我的AutoHotkey脚本
热门文章
- Bouncycastle中的RSA技术以及解决之道
- winform实现word转换为PDF(.doc)
- Java compiler level does not match the version of the installed Java project facet.	springmvc1 和 Target runtime Apache Tomcat v7.0 is not defined.
- c++101rule
- kafka_2.11-0.8.2.2的搭建
- DBA_Oracle冷备份和热备份的处理(概念)
- hdu 1532 Dinic模板(小白书)
- studio adb连接不上手机 ADB server didn&#39;t ACK
- 冲突--ListView与ScrollView冲突的4种解决方案
- jquery extend中