HDU-1166(树状数组入门)
来源:互联网 发布:ubuntu安装wine2.0 编辑:程序博客网 时间:2024/05/29 15:16
这道题目,一看就是用树状数组写的嘿嘿.
不错,一次性就写成功了嘿嘿.
主要需要注意的点就是,询问的时候,由于是询问的区间,包括两边,所以你只能减去开头 往前面输一个 的营地的总和,,,
贴出代码:
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>int N;int T;int ar[50005];int lowb(int t){return t&(-t);}void add(int t,int v){for(int i=t;i<50005;i+=lowb(i)){ar[i]+=v;}}int sum(int t){int s=0;for( int i=t; i>0 ;i-=lowb(i)){s+=ar[i];}return s;}int main(){scanf("%d",&T);int k=1;int t1,t2;while(T--){int a;char s[20];scanf("%d",&N);memset(ar,0,sizeof(ar));for(int i=1;i<=N;i++){scanf("%d",&a);add(i,a);}printf("Case %d:\n",k++);//for(i=1;i<=N;i++)//{//printf("%d___",ar[i]);//}//printf("\n");while(scanf("%s",s)&&strcmp(s,"End")){scanf("%d%d",&t1,&t2);if(strcmp(s,"Sub")==0){add(t1,-t2);}else if(strcmp(s,"Add")==0){add(t1,t2);}else if(strcmp(s,"Query")==0){int m1=sum(t1-1);int m2=sum(t2);//printf("%d@@@@%d\n",m1,m2);printf("%d\n",m2-m1);}}}return 0;}
- HDU-1166(树状数组入门)
- hdu 1166 树状数组 入门题
- hdu 1166 敌兵布阵【树状数组入门】
- hdu 1166 树状数组 线段树入门
- 树状数组入门 之 hdu 1166
- [HDU 1166]敌兵布阵[树状数组][入门]
- HDU-1541(树状数组入门)
- hdu 1541 树状数组入门
- hdu 1166 树状数组
- hdu 1166(树状数组)
- HDU 1166树状数组
- HDU 1166 树状数组
- HDU 1166 树状数组
- HDU 1166 树状数组
- hdu 1166 树状数组
- HDU 1166 树状数组
- HDU 1166 敌兵布阵 线段树/树状数组入门题
- HDU 1166 敌兵布阵 (树状数组入门)
- 46.VC(custom)-windows路径操作相关API函数
- 各种地图的初始化方法
- oracle 查看用户所在的表空间
- 傻傻svn
- select和poll函数
- HDU-1166(树状数组入门)
- 没有为类型 ServiceContext 定义方法 invokeBreak()
- 新的一天1080
- 传输层-http协议简介
- Json拼接字符串必须用双引号
- Gentoo、Debian、FreeBSD的软件包管理方式
- 移动互联网产品设计的原则
- 替换sql查询非法字符
- 规则引擎Ilog Jrules开发基础教程【连载1】-- 概述篇