HDU4970 Killing Monsters dp
生活随笔
收集整理的這篇文章主要介紹了
HDU4970 Killing Monsters dp
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題意:給你n個(gè)操作,每一次對(duì)區(qū)間相加,詢問區(qū)間和。
解題思路:這里沒有動(dòng)態(tài)更新, 所以我們用括號(hào)匹配那種方法就行 就是 a[l] + x ?,a[r+1] -x 這種做法。
解題代碼:
1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <math.h> 5 #define MAX 100005 6 #define LL long long 7 LL a[100005]; 8 int main() 9 { 10 int n; 11 while(scanf("%d",&n) != EOF,n) 12 { 13 memset(a,0,sizeof(a)); 14 int tsum ; 15 scanf("%d",&tsum); 16 for(int i =1 ;i<=tsum ;i ++) 17 { 18 int ta,tb,tc; 19 scanf("%d %d %d",&ta,&tb,&tc); 20 a[ta] += tc; 21 a[tb+1] -= tc; 22 } 23 LL sum = 0 ; 24 LL ta = 0 ; 25 for(int i = 1;i <= n;i ++) 26 { 27 ta += a[i]; 28 sum += ta; 29 a[i] = sum; 30 //printf("%I64d ",a[i]); 31 } 32 //printf("\n"); 33 scanf("%d",&tsum); 34 int ans = 0 ; 35 for(int i = 1;i <= tsum ;i ++) 36 { 37 LL ta,tb; 38 scanf("%I64d %I64d",&ta,&tb); 39 if(a[n] - a[tb-1] < ta) 40 { 41 ans ++ ; 42 } 43 } 44 printf("%d\n",ans); 45 46 } 47 return 0 ; 48 } View Code?
轉(zhuǎn)載于:https://www.cnblogs.com/zyue/p/3923566.html
總結(jié)
以上是生活随笔為你收集整理的HDU4970 Killing Monsters dp的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: (转)start_kernel 代码分析
- 下一篇: (转)jQuery.fn.extend与