posts - 21, comments - 2, trackbacks - 0, articles - 0

HDU 1166敌兵布阵

Posted on 2011-09-01 17:14 acpeng 阅读(174) 评论(0)  编辑 收藏 引用 所属分类: ACM程序
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166
初学线段树,本想些个树,写了一半实在是觉得没必要,此题直接用数组模拟,果断AC,1Y~~~
#include<stdio.h>
#include
<string.h>
int data[50003];
int main()
{
    
int T,N,i,cont=1;
    
int cd_1,cd_2,sum;
    
char comd[7]="\0";
    scanf(
"%d",&T);
    
while(T--)
    
{
        scanf(
"%d",&N);
        printf(
"Case %d:\n",cont);
        cont
++;
        
for(i=0;i<N;i++)
            scanf(
"%d",&data[i]);
        scanf(
"%s",comd);
        
while(strcmp(comd,"End")!=0)
        
{
            scanf(
"%d%d",&cd_1,&cd_2);
            
if(comd[0]=='A')
                data[cd_1
-1]+=cd_2;
            
else if(comd[0]=='S')
                data[cd_1
-1]-=cd_2;
            
else if(comd[0]=='Q')
            
{
                sum
=0;
                
for(i=cd_1-1;i<cd_2;i++)
                    sum
+=data[i];
                printf(
"%d\n",sum);
            }

            memset(comd,
0,sizeof(comd));
            scanf(
"%s",comd);
        }

    }

    
return 0;
}


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理