6609 - Minimal Subarray Length】的更多相关文章

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4620 You are given an integer sequence of length N and another value X. You have to find a contiguoussubsequence of the given sequence such t…
题意:给定长度为N的数组,求一段连续的元素之和大于等于K,并且让这段元素的长度最小,输出最小长度即可,若不存在这样的元素集合,则输出-1 题目链接:UVAlive 6609 做法:做一个前缀和prefix,然后再作一个维护前缀和最大值数组Max,枚举所有可能的起始点i,在Max上二分末尾位置r,由于Max维护的是前缀和的最大值,因此具有单调性,可以进行二分,似乎还有其他O(n)的做法,有空去膜一下 代码: #include <stdio.h> #include <bits/stdc++.…
描述:给定n个整数元素,求出长度最小的一段连续元素,使得这段元素的和sum >= X. 对整个数组先求出sum[i],表示前i个元素的和,然后依次求出以a[i]为起点的,总和>= X的最小长度, 每次考虑新元素a[i]时,将a[i]加入数组, pa[-q] = mp(sum[i], i),这样pa[q---.p]形成一段总和递增的序列,下标也是逐渐增大. 最后利用lower_bound函数求出大于或等于sum[i-1]+X的最左边的元素,求出以i为起点最短长度. 最后想了一下如果是求>=…
Minimal Subarray Length Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Original ID: 660964-bit integer IO format: %lld      Java class name: Main     You are given an integer sequence of length N and another value X…
题目链接 题意:给出n个数,求加和大于x的最短区间的区间长度. 如果前i个数字和为y,那么如果前j数字的和小于等于y-x,那么i-j就是一种可能的情况,我们对于所有的i找出前面最大的j就可以了,因为数据量比较大,用树状数组来处理前n项的最大值,但是每个数字又可能比较大,所以先离散化处理一下. AC代码 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 typedef long long LL;…
第一次的增补赛,也是第一场个人排位赛,讲道理打的和屎一样,手速题卡了好久还WA了好多发,难题又切不出来,这种情况是最尴尬的吧! Individual Contest #1: Ploblem D: 题意:给你一个含有N个元素的数组和操作次数m,然后求出经过m次操作后,从区间X到Y的总和:操作如下:{1,6,9}==>{1,7,6,15,9}(多CASE) 题目链接:https://www.codechef.com/problems/CHSPARR 思路: 首先,最容易想到的是单纯的模拟每一次这样的…
Given an array consisting of n integers, find the contiguous subarray whose length is greater than or equal to k that has the maximum average value. And you need to output the maximum average value. Example 1: Input: [1,12,-5,-6,50,3], k = 4 Output:…
Given a list of non-negative numbers and a target integer k, write a function to check if the array has a continuous subarray of size at least 2 that sums up to the multiple of k, that is, sums up to n*k where n is also an integer. Example 1: Input:…
Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King's castle. The King was so greedy, that he would not listen to his Architect's proposals to build a beautiful brick wall with a perfec…
Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10403    Accepted Submission(s): 4033 Problem Description There are a lot of trees in an area. A peasant wants to buy a rope to…