LA2678
来源:互联网 发布:mac的桌面 编辑:程序博客网 时间:2024/05/01 14:41
题目大意:
求大于S的最短连续子序列的长度
代码:
#include <iostream>using namespace std;#include <stdio.h>#include <cstring>int A[100005];int B[100005];int main() { int n,S; while(~scanf("%d %d",&n,&S)) { B[0] = 0; for(int i = 1; i <= n; i++) scanf("%d",&A[i]); for(int i = 1; i <= n; i++) { B[i] = B[i - 1] + A[i]; } int ans = n + 1; int i = 1; for(int j = 1; j <= n; j++) { if(B[j] - B[i - 1] < S) continue; while(B[j] - B[i] >= S) i++; ans = min(ans,j - i + 1); } printf("%d\n",ans == n +1?0:ans); }}
0 0
- LA2678
- La2678
- 尺取法+LA2678
- UvaLive LA2678 Subsequence
- LA2678最短子序列
- LA2678 Subsequence 时间优化
- LA2678 Subsequence 时间优化
- la2678(前缀和,二分/尺取法)
- LA2678 - Subsequence(求序列中长度最短的和>=S的子序列长度)
- 驱动大尺寸数码管的方法与电路
- linux下清除svn账号和密码
- P1 接 8 个独立按键,P2 接 8 个 LED,要求用按键控制 LED 的发光状态
- 设计一个显示ASCII码的程序
- 统计一个字符串中某个字母的个数
- LA2678
- C语言编程:8051单片机系统的时钟为11.0592MHz,把0~99从串行口输出
- 四个按键控制四个数字递增
- VS2015 ERROR
- 用C语言按照冒泡法进行数字排序
- C++ STL--stack/queue 的使用方法
- DEBUG里标志寄存器状态位英文全称
- WC四校联考总结
- 51单片机汇编语言编程:用定时器控制输出矩形波