CSU1350 To Add which?
题目链接:
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1350
这题目因为每一个数都跟相邻的数有关,所以可以从左到右和从右到左一次扫一遍即可
代码:
#include<iostream>
#include<cstdio>
#define M 100100
using namespace std; int num[M],Max[M],Min[M]; int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
int T,n,D;
long long ans;
cin>>T;
while(T--){
ans=;
cin>>n>>D;
for(int i=;i<n;i++) cin>>num[i]; Max[]=num[];
for(int i=;i<n;i++)
{
if(Max[i-]-num[i]>D)
Max[i]=Max[i-]-D;
else Max[i]=num[i];
} Min[n-]=num[n-];
for(int i=n-;i>=;i--)
{
if(Min[i+]-num[i]>D)
Min[i]=Min[i+]-D;
else Min[i]=num[i];
} for(int i=;i<n;i++) ans+=(max(Min[i],Max[i])-num[i]);
cout<<ans<<endl;
}
return ;
}
CSU1350 To Add which?的更多相关文章
- AutoMapper:Unmapped members were found. Review the types and members below. Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type
异常处理汇总-后端系列 http://www.cnblogs.com/dunitian/p/4523006.html 应用场景:ViewModel==>Mode映射的时候出错 AutoMappe ...
- EntityFramework Core 1.1 Add、Attach、Update、Remove方法如何高效使用详解
前言 我比较喜欢安静,大概和我喜欢研究和琢磨技术原因相关吧,刚好到了元旦节,这几天可以好好学习下EF Core,同时在项目当中用到EF Core,借此机会给予比较深入的理解,这里我们只讲解和EF 6. ...
- ASP.NET Core: You must add a reference to assembly mscorlib, version=4.0.0.0
ASP.NET Core 引用外部程序包的时候,有时会出现下面的错误: The type 'Object' is defined in an assembly that is not referenc ...
- [转]NopCommerce How to add a menu item into the administration area from a plugin
本文转自:http://docs.nopcommerce.com/display/nc/How+to+code+my+own+shipping+rate+computation+method Go t ...
- [deviceone开发]-动态添加组件add方法的示例
一.简介 这个示例详细介绍ALayout的add方法的使用(原理也适用于Linearlayout),以及add上去的新ui和已有的ui如何数据交换,初学者推荐.二.效果图 三.相关下载 https:/ ...
- [LeetCode] Add Two Numbers II 两个数字相加之二
You are given two linked lists representing two non-negative numbers. The most significant digit com ...
- [LeetCode] Add Strings 字符串相加
Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. ...
- [LeetCode] Expression Add Operators 表达式增加操作符
Given a string that contains only digits 0-9 and a target value, return all possibilities to add ope ...
- [LeetCode] Add Digits 加数字
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...
随机推荐
- servlet生命周期:
Servlet生命周期分为三个阶段: 1,初始化阶段 servlet实例创建时调用init()方法,在Servlet的整个生命周期内,init()方法只被调用一次. 2,响应客户请求阶段 调用ser ...
- 2019/05/11 Java内存结构
1. 类加载子系统:负责从文件系统或者网络加载Class信息,加载的信息存放在一块称之方法区的内存空间. 2. 方法区:就是存放类的信息.常量信息.常量池信息.包括字符串字面量和数字常量等. 3. ...
- AJPFX总结之Socket编程
一.Socket简介 Socket是进程通讯的一种方式,即调用这个网络库的一些API函数实现分布在不同主机的相关进程之间的数据交换. 几个定义: (1)IP地址:即依照TCP/IP协议分配给本地主机的 ...
- 通过流传入excel解析的问题
做了个excel文件导入的功能,接收excel文件流,先读取文件流头部信息确定文件类型,然后调用poi方法 OPCPackage pkg = OPCPackage.open(inputStream) ...
- 洛谷P3254 圆桌问题(最大流)
题意 $m$个不同单位代表参加会议,第$i$个单位有$r_i$个人 $n$张餐桌,第$i$张可容纳$c_i$个代表就餐 同一个单位的代表需要在不同的餐桌就餐 问是否可行,要求输出方案 Sol 比较zz ...
- Android 常见的工具类
/** * Wifi 管理类 * * @author Administrator * 使用方法 * WifiManagerUtils wifiManager = new WifiManagerUtil ...
- CCF|中间数|Java
import java.util.*; public class tyt { public static void main(String[] args) { Scanner in = new Sca ...
- IOS 根据身份证号码获取 年龄 生日 性别
/** 从身份证上获取年龄 18位身份证 */ -(NSString *)getIdentityCardAge:(NSString *)numberStr { NSDateFormatter *for ...
- 激活eclipse自动提示功能
eclipse设置: Window->Preferences->Java->Editor->Content Assist
- jq获取设置选中值
var standard = $('input[name="standard"]:checked').val(); $("input[name='advertByid'] ...