玲珑学院-1014-Absolute Defeat【思维】
来源:互联网 发布:北京理工大学网络登录 编辑:程序博客网 时间:2024/05/18 04:44
题目链接:点击打开链接
1014 - Absolute Defeat
Time Limit:2s Memory Limit:64MByte
Submissions:262Solved:76
DESCRIPTION
Eric has an array of integers a1,a2,...,ana1,a2,...,an. Every time, he can choose a contiguous subsequence of length kk and increase every integer in the contiguous subsequence by 11.He wants the minimum value of the array is at least mm. Help him find the minimum number of operations needed.
INPUT
There are multiple test cases. The first line of input contains an integerTT, indicating the number of test cases. For each test case:The first line contains three integersnn,mm and kk(1≤n≤105,1≤k≤n,1≤m≤104)(1≤n≤105,1≤k≤n,1≤m≤104).The second line contains nn integers a1,a2,...,ana1,a2,...,an(1≤ai≤104)(1≤ai≤104).
OUTPUT
For each test case, output an integer denoting the minimum number of operations needed.
SAMPLE INPUT
3
2 2 2
1 1
5 1 4
1 2 3 4 5
4 10 3
1 2 3 4
SAMPLE OUTPUT
1
0
15
题意:给你一个长度为 n 的序列,然后你每次只能处理长度为 k 子序列,每次处理使这长度为 k 的子序列每个值加 1,问最少要处理几次才能使整个序列的每个元素都大于 m
#include<cstdio>#include<algorithm>#include<cstring>using namespace std;const int MAX=1e5+10;int n,m,k;int a[2*MAX];int main(){int t;scanf("%d",&t);while(t--){scanf("%d %d %d",&n,&m,&k);memset(a,0,sizeof(a));int x,ans=0;for(int i=1;i<=n;i++){scanf("%d",&x);a[i]+=a[i-1];if(x+a[i]<m) // 每次的 a[i]只有两个值要么是 n*k,要么是 0 {int step=m-a[i]-x;ans+=step;a[i]+=step;a[i+k]-=step; // 每次处理的长度只有 k,而上面还有个累加,所以这里先把第 i+k位减 step, } // 这样就保证了上面判断的 a[i],只可能是 两种值 }printf("%d\n",ans);}return 0;}
0 0
- 玲珑学院-1014-Absolute Defeat【思维】
- 玲珑学院-ACM比赛1014 - Absolute Defeat
- 玲珑学院OJ 1014 - Absolute Defeat(智商暴力题)
- 玲珑杯 1014 - Absolute Defeat
- 【1014 - Absolute Defeat】
- Lonlife-ACM 1014 - Absolute Defeat [差分]
- 玲珑学院OJ 1071 Boring Game【思维】
- 玲珑学院-1010-Alarm【打表】【找规律】【思维】
- 玲珑学院OJ 1020 Grand Master【思维+并查集】
- 玲珑学院OJ 1101 萌萌哒的第六题【思维枚举】
- 玲珑学院 1058 - Coco
- 玲珑学院problem1068
- 玲珑学院1072 【DFS】
- 玲珑学院 1097
- 玲珑学院-1107【贪心】
- 玲珑学院OJ 1126
- 玲珑学院OJ 1125
- 玲珑学院OJ 1131
- CSU 1111: 三家人【有趣的思维题】
- 网页放在WEB-INF下面怎样发布访问
- WebView的简单学习20160820
- Spring MVC Fast Tutorial: Model View Controller
- Qt中pro文件的详细介绍
- 玲珑学院-1014-Absolute Defeat【思维】
- Arithmetic problem | 统计前面比自己小的数的个数
- Java并发编程番外篇(二)happens-before关系
- BZOJ 1051 Tarjan
- Oracle笔记002
- getopt(3)
- android studio 启动问题
- AMS-总结
- python之路