E. Bus Video System(找刚开始车上,满足的人数,好题,细节多)

Bus Video System CodeForces - 978E(水题 思维) E. Bus Video Systemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe busses in Berland are equipped with a video surveillance system. The system ... 阅读详情

E. Bus Video System
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops.

If xx is the number of passengers in a bus just before the current bus stop and yy is the number of passengers in the bus just after current bus stop, the system records the number y−xy−x. So the system records show how number of passengers changed.

The test run was made for single bus and nn bus stops. Thus, the system recorded the sequence of integers a1,a2,…,ana1,a2,…,an (exactly one number for each bus stop), where aiai is the record for the bus stop ii. The bus stops are numbered from 11 to nn in chronological order.

Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to ww (that is, at any time in the bus there should be from 00 to ww passengers inclusive).

Input

The first line contains two integers nn and ww (1≤n≤1000,1≤w≤109)(1≤n≤1000,1≤w≤109) — the number of bus stops and the capacity of the bus.

The second line contains a sequence a1,a2,…,ana1,a2,…,an (−106≤ai≤106)(−106≤ai≤106), where aiai equals to the number, which has been recorded by the video system after the ii-th bus stop.

Output

Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to ww. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0.

Examples
input
Copy
3 5
2 1 -3
output
Copy
3
input
Copy
2 4
-1 1
output
Copy
4
input
Copy
4 10
2 4 1 2
output
Copy
2
Note

In the first example initially in the bus could be 00, 11 or 22 passengers.

In the second example initially in the bus could be 11, 22, 33 or 44 passengers.

In the third example initially in the bus could be 00 or 11 passenger.


题意:输入 n,m,n为有n站,m为公交车的容量,下面一行有n个数,为n站上下车的情况,看看刚开始车上可以有多少种情况,满足 给出 n 站的数据,要是没有输出0,要是有,输出 多少种情况;

思路:这道题细节多,找出车上的上限和下限,在看看有没有交叉的情况,一定要注意交叉的情况;

代码中有解释:

#include<stdio.h>  
#include<string.h>  
#include<algorithm>  
using namespace std;  
  
#define Max 100010  
#define INF 0x3f3f3f3f  
#define ll long long   
ll a[Max];  
int main()  
{  
    int i,j,n,m;  
    while(~scanf("%d%d",&n,&m))  
    {  
        int x;  
        int ma = -INF;  
        int sum = 0;    
        int mi = INF;  
        for(i = 0;i<n;i++)  
        {  
            scanf("%d",&x);  
            sum += x;  
            ma = max(ma,sum);     
            mi = min(mi,sum);   //   
        }  
        // ma  找出来最大,当 ma为非负时,刚开始在车上的人数,上限不能超过 m - ma;  
        // mi 找出最小,当 mi 为非正时,更开始在车上的人数,下限不能低于 -mi;    
        // 下限不能超过 上限;超过就是0;
		// 一定要记住 ma 可能小于0,mi可能大于0;  
		if(ma>m||mi<-m||m-ma<(-mi))  // 下限不能大于上线; 
		{
			printf("0\n");
			continue;
		}
		int tt = m;
		int flag = 0;
		if(ma>=0)                     // ma可能为小于0 ;那么上限就是m了 
		{
			tt = m - ma + 1;
			flag = 1;
		}
		if(mi<=0)                    // mi 可能大于0; 
		{
			if(flag) tt = tt-(-mi);
			else tt = tt + mi + 1; 
		}	
		printf("%d\n",tt);
       } 
    return 0;  
}  

Amos中介效应检验为何必须用Bootstrap法 中介效应检验是社会科学实证研究的核心方法,其本质在于评估自变量通过中介变量影响因变量的间接路径强度。传统Sobel检验依赖ab乘积项的正态分布假设,但在小样本(n<200)、路径系数不对称或残差偏态等常见情形下极易失效,导致统计效力下降和假阴性增加。Bootstrap重抽样技术通过经验分布构建置信区间,规避了正态性约束,显著提升检验稳健性与结果可复现性。该方法在心理学、管理学及公共卫生等领域已成为发表级标准,尤其适用于Amos等结构方程软件中的潜变量中介模型分析。 阅读详情

相关推荐

xxx.rar_xxx video_xxx.CBp.VDO_xxx.video._视频 解压缩

视频图像的编解码,将原始图像压缩成MPEG4格式,然后在客户端解压缩显示

Bus Video System CodeForces - 978E(思维)

题意:现有n个公交车站,给出每个公交车站上下车的人数变化,正为上车,负为下车,公交车的最大容量为w。问,最开始时,公交车的可能人数有多少种。如果任何人数都与后面给出的上下情况冲突的话,输出0. 直接看AC代码: #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; const int maxn=1e6+5; in

Alanrookie的博客 1069

STM32F103模拟SSI时序解析:实现高精度绝对式编码器位置读取

本文详细解析了如何在STM32F103微控制器上通过软件模拟SSI协议时序,实现高精度绝对式编码器的位置读取。文章从项目驱动出发,深入剖析了SSI通信原理、硬件电平转换连接、核心软件模拟代码实现及关键时序参数调试方法,并提供了使用示波器进行波形对齐与优化的实战指南,为成本敏感型工业控制与机器人项目提供了高性价比的解决方案。

weixin_29196315的博客 143

video使用

<video class="video_box" width="100%" height="100%" webkit-playsinline="webkit-playsinline" x5-playsinline="x5-playsinline" x5-video-player-type="h5" x5-video-player-fullscreen="" playsinline="playsinline" preload="auto" poster="https://xxx/poster.png"

一只快乐的小猴子的博客 2万+

线性代数——(期末突击)行列式(上)-行列式计算、行列式的性质

简单解释一下:4213原本的顺序应为1234,对于‘4’而言,‘2’、‘1’、‘3’都应该排在它的前面,所以此处记逆序数为3;对于‘2’而言,‘1’应该排在它的前面,而‘3’排在它之后 是合理的,所以此处只有一个逆序数;最后看‘1’,其后面的‘3’排在后面显然也是合理的,故而4213的逆序数为4.一般我们使用这个性质来计算四阶行列式,也就是将其变换成三角行列式,再计算对角线的值;以主对角线为分界线的就为正三角,反之则为反三角行列式。若行列式某一行(列)为0,则该行列式=0.将和的那一行分开,其余行。

li13437542099的博客 1万+

【回眸】Tessy集成测试软件使用指南(一)新手使用篇

这个专栏的文章前4篇都在记录如何使用Tessy进行单元测试,集成测试需要有一定单元测试基础,且做集成测试之前,需要做好单元测试,否则将会大幅增加软件单元代码纠错的代价。集成测试所花费的时间通常远远超过单元测试。如果直接从单元测试到系统测试,结果往往是不理想的。集成测试可以检测由于单元相互交互而导致的错误,通常由一组专业的测试人员执行。

啤酒鸭的物联网开发记录博客 5311

cf----2019-10-12(Bus Video System,Bus Video System,Petya's Exams)

一场游戏一场空,最终最初都由我掌控,好像一身从容,不曾有狼狈伤痛,可深夜一个人该如何相拥? The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a b...

0k-ok 7059

C++面试八股文

和静态多态(又称编译期多态,即在系统编译期间就可以确定程序将要执行哪个函数),其中动态多态是通过虚函数实现的,虚函数是类的成员函数,存在存储虚函数指针的表叫做虚函数表,虚函数表是一个存储类成员虚函数的指针,每个指针都指向调用它的地方,当子类调用虚函数时,就会去虚表里面找自己对应的函数指针,从而实现“谁调用、实现谁”从而实现多态。而C++符号表中的符号不是以函数名命名的,称为函数名修饰规则,虽然函数名相同,但是函数参数等其他属性不同,取的符号也不同,所以不会产生查询歧义的问题,使得函数可以重载。

qq_46676829的博客 911

Bus Video System CodeForces - 978E (思维)

The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. Ifxxis the number of passengers i...

weixin_30299709的博客 458

Open3D (C++) 使用点云创建数字高程模型DEM

Open3D (C++) 使用点云创建数字高程模型DEM

点云侠的博客 1394

【异常】安装hermes-agent提示Git克隆仓库网络中断 fetch-pack: unexpected disconnect while reading sideband packet

本文分析了Git克隆仓库时出现网络中断错误的常见原因及解决方案。报错表现为连接被远程主机关闭、管道破裂或数据包意外终止,通常由网络不稳定、仓库过大或配置不当引起。提供了5种优先级排序的解决方法:1)使用浅克隆减少数据量;2)优化Git配置参数;3)切换网络或配置代理;4)检查SSH密钥设置;5)改用HTTPS方式克隆。特别推荐先尝试「浅克隆+HTTPS」组合方案快速验证,若问题持续再根据具体报错深入排查。文中包含详细的命令示例和配置说明,适合不同网络环境下的Git用户参考。

奶爸的编程之路,也就一周冷个三天 1431

E. Bus Video System

E. Bus Video System time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output The busses in Berland are equipped with a video surveillance system. T...

小自洽 3842

MTK Meta ISP 工具使用技巧与参数读取路径全解析

在联发科(MediaTek, MTK)平台上进行相机图像调试时,Meta ISP 工具是连接 PC 与设备进行参数调整、寄存器读取和图像输出的重要工具。本文以实战角度出发,系统梳理 Meta ISP 的使用流程、关键模块功能、典型调试技巧与参数读取路径,结合最新版平台(如MTK Genio/Dimensity 系列)架构,帮助工程师掌握联发科图像调优的核心流程。

努力分享一些人工智能、计算机视觉、影像等相关的知识干货! 1164

codeforces 978E - Bus Video System(数学思想去做)

E. Bus Video System time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The busses in Berland are equipped with a video surveillance s...

bjfu170203101的博客 395

如何修改网页中的文本内容改成自己希望的数值?

本篇文章主要讲解,通过浏览器命令和浏览器自带的F12开发者工具,进行修改网页内容的方法教程 日期:2021年12月5日 作者:任聪聪 一、通过F12开发者工具进行修改 进入方式汇总: 1.右击鼠标,显示菜单找到审查 2.通过快捷键F12进入,笔记本需要先关闭fnlk功能键。 开发者工具介绍 说明: 1.表示选择元素,点击后可以选择文本的元素所在地 2.表示显示方式,手机还是电脑 3.表示div元素,点击后可以展开,对div内的html和文本进行编辑。 双击文本,即可进行修改成自己想要的,但是刷新后.

任聪聪的博客 2万+

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

codeforces978E Bus Video System

The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops.If x is the number of passengers in a...

adobemomo的博客 444

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Codeforces Round #481 (Div. 3) E. Bus Video System

题目链接 题意: 给n个车站,和一辆载人数为w的公交车。给出到达每个车站之后,车上的人的变化数量。问:最初车上有多少情况(多少人数),如果没有一种情况符合,或者说给出的数据是矛盾的,输出0。 思路 既然载人数为w,那先啥都不管,最初可能有(0,1,2,3,4,5…w)中情况(最初的车上的人数)。那么我们知道,这么多种情况肯定有些是不符合的,比如经过第一个车站后,车上人数变化为-3,那么车上至少要有...

give it a try 191

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

CF Round 481 (Div. 3)--E. Bus Video System(二分)

The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. Ifxis the number of passengers in a bus just before the current bus stop andyis the num

小小小Why的博客 254

CodeForces - 978E·Bus Video System

题目 题目大意 分析 代码 题目 传送门 题目大意 一辆公交车上最多能乘www( 1≤w≤1091≤w≤1091\leq w\leq 10^9)个人,公交车发车后会依次在nnn(1≤n≤10001≤n≤10001\leq n\leq 1000)个站停车,车上的一个系统会记录每次停站前后车上人数的差,现在给你这些差值,问公交车发车时车上可能有多少人,输出方案数。 分...

ixRic 823

978E Bus Video System

The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. Ifxxis the number of passenger...

学习笔记 1725

CodeForces978E Bus Video System(模拟&细节)

The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops.If xx is the number of passengers in ...

UncleJokerly 732

cf978E Bus Video System

The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. Ifxxis the number of passeng...

weixin_30906425的博客 195
上一篇: 一维战舰 51Nod - 1521 (set 二分查找,判断撒谎)
下一篇: Codeforces Round #481 (Div. 3) G. Petya's Exams(贪心)
obsorb_knowledge
博客等级 码龄9年 38粉丝 213原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值