码迷,mamicode.com
首页 > 其他好文 > 详细

NYOJ108

时间:2014-10-31 19:20:20      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:nyoj 108 士兵杀敌

// 思路就是:数组第i项存储的是前i个(包括第i个)士兵的杀敌数


#include <stdio.h>

#include <stdlib.h>

#include <string.h>


int main()

{

int num_of_soldiers, num_of_asks, from, to;

int total_kills[100001];

int i, num_of_kills;


memset(total_kills, 0, sizeof(total_kills));

        scanf("%d %d", &num_of_soldiers, &num_of_asks);

for (i = 1; i <= num_of_soldiers; i++)

{

scanf("%d", &num_of_kills);

total_kills[i] = total_kills[i - 1] + num_of_kills;

}


while (num_of_asks--)

{

scanf("%d %d", &from, &to);

printf("%d\n", total_kills[to] - total_kills[from - 1]);

}

        

        return EXIT_SUCCESS;

}


NYOJ108

标签:nyoj 108 士兵杀敌

原文地址:http://mjmctt.blog.51cto.com/3471180/1570440

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!