[IOI2005]mea
2024-10-20 17:28:07
IOI
读完题,感觉这个题并不是很难,那我是不是可以去IOI了:
最先考虑暴力,发现完全行不通,所以,我们考虑其他方法。突然发现:其实在确定 \(s_1\) 的时候,整个序列就可以确定了,所以我们考虑对 \(s_1\) 进行操作
通过题目中给出的条件,容易发现这个值与奇偶性有关系,所以 code:
注意在答案为负的情况下判 0
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#define int long long
using namespace std;
namespace xin_io
{
inline int get()
{
int s = 0,f = 1;
register char ch = getchar();
while(!isdigit(ch))
{
if(ch == '-') f = -1;
ch = getchar();
}
while(isdigit(ch))
{
s = s* 10 + ch - '0';
ch = getchar();
}
return s * f;
}
inline void openfile()
{freopen("t.txt","r",stdin);}
inline void outfile()
{freopen("o.txt","w",stdout);}
}
using xin_io::get; using xin_io::openfile; using xin_io::outfile;
namespace xin
{
int mx = 1ll<<60ll,mn = -mx;
int now,i,x,y,n;
inline short main()
{
n = get();
for (i = 1; i <= n; ++i, y = x)
{
x = get();
if (i & 1) now += x - y,mx = min(mx, now);
else now += y - x,mn = max(mn,now);
}
printf("%lld\n", mx < mn ? 0 : mx - mn + 1);
return 0;
}
}
signed main() {return xin::main();}
最新文章
- python头部注释 vim添加头部注释
- 用PS设计等高线效果的背景图片
- Node-webkit简介
- python子类调用父类的方法
- Android WIFI 启动流程
- Struts2 请求参数接收
- hash在Coreseek 中配置bigint
- 【百度地图API】建立全国银行位置查询系统(三)——如何在地图上添加银行标注
- Windows下快速安装Xgboost(无需Git或者VS)
- 嵌入式 RTP通话:视频流(H.264)的传输
- Text Document Analysis CodeForces - 723B
- 通过javap终极理解++i和i++的区别
- jenkins默认会存放目录
- 1040 有几个PAT
- windows迁移linux问题集锦
- c++学习之多态(虚函数和纯虚函数)
- 关于JQueryMobile中Slider的一点研究
- 项目总结之HashMap问题
- jquery-validate校验
- 高手从零开始的全定制发行版-Linux from Scratch
热门文章
- Centos 安装 Influxdb + Chronograf
- 【逆向实战】ES文件浏览器未授权访问漏洞(CVE-2019-6447)具体分析及利用
- 『心善渊』Selenium3.0基础 — 1、Selenium自动化测试框架介绍
- 『动善时』JMeter基础 — 47、JMeter的HTTP代理服务器详细介绍
- 惊艳面试官的 Cookie 介绍
- 远程连接MySQL错误“plugin caching_sha2_password could not be loaded”的解决办法
- Java并发之ReentrantLock源码解析(二)
- 从零开始学前端,React框架背后的核心机制和原理JSX
- 5、修改oracle的字符集
- solidity 小案例 收费站