题意:给你含有n个数的序列,每次你可以选一个子序列将上面所有的数字加1或者减1,目标是把所有数字变成相同的,问最少步数,和那个相同的数字有多少种可能。

将原序列转化为差分序列,即a[2] - a[1], a[3] -a[2]……, a[n] - a[n -1]

将原序列l,到r增加1,相当于差分序列l处加1,r + 1减1,讲从l处到尾加1,相当于差分序列l处加1

减法与此类似

故将差分序列中元素正负可以相消,总的次数为正数和与负数和绝对值的最大值。

最终变换后的序列值可取a[1]到a[n]的每个数(还没想到怎么证明)

#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
using namespace std;
typedef long long LL;
const int N = 1000008, INF = 0x3F3F3F3F;
int a[N];
int main(){
int t;
cin>>t;
for(int cas = 1; cas <= t; cas++){
int n;
scanf("%d", &n);
LL s1 = 0, s2 = 0;
for(int i = 0; i < n; i++){
scanf("%d", &a[i]);
if(i){
if(a[i] > a[i - 1]){
s1 += a[i] - a[i - 1];
}else{
s2 += a[i - 1] - a[i];
}
}
}
printf("Case %d: %I64d %I64d\n", cas, max(s1, s2), abs((LL)a[0] - a[n - 1]) + 1ll);
} return 0;
}

  

HDU3434 Sequence Adjustment的更多相关文章

  1. [C7] Andrew Ng - Sequence Models

    About this Course This course will teach you how to build models for natural language, audio, and ot ...

  2. oracle SEQUENCE 创建, 修改,删除

    oracle创建序列化: CREATE SEQUENCE seq_itv_collection            INCREMENT BY 1  -- 每次加几个              STA ...

  3. Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等

    功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...

  4. DG gap sequence修复一例

    环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...

  5. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  6. [LeetCode] Sequence Reconstruction 序列重建

    Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...

  7. [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  8. [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列

    Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...

  9. [LeetCode] Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

随机推荐

  1. django的跨站请求访问

    一.简介 django为用户实现防止跨站请求伪造的功能,通过中间件 django.middleware.csrf.CsrfViewMiddleware 来完成.而对于django中设置防跨站请求伪造功 ...

  2. Best Meeting Point

    Total Accepted: 701 Total Submissions: 1714 Difficulty: Medium A group of two or more people wants t ...

  3. mysql性能优化学习笔记-参数介绍及优化建议

    MySQL服务器参数介绍 mysql参数介绍(客户端中执行),尽量只修改session级别的参数. 全局参数(新连接的session才会生效,原有已经连接的session不生效) set global ...

  4. unity3d项目文件目录发布后,对应的ios/android应用目录[转]

    Unity3d的Resource.AssetBundle与手游动态更新的报告,在这里分享一下,希望能够对各位用Unity的朋友有些许帮助.目录:1.Unity的资源数据加载2.Resource.Str ...

  5. Java for LeetCode 204 Count Primes

    Description: Count the number of prime numbers less than a non-negative number, n. 解题思路: 空间换时间,开一个空间 ...

  6. Maven 3.3.3 Win10环境下的使用实例(下)

    这一篇文章将介绍如何在 Eclipse 中使用 Maven. 我们以 Eclipse Java EE 版本为例,首先要对 IDE 进行一些设置: JDK 环境 Maven 的本地安装路径 Maven ...

  7. HDU 4966 GGS-DDU(最小树形图)

    n个技能,每个技能有0-a[i]的等级,m个课程,每个课程需要前置技能c[i]至少达到lv1[i]等级,效果是技能d[i]达到lv2[i]等级,花费w[i]. 输出最小花费使得全技能满级(初始全技能0 ...

  8. 【leetcode】Merge Two Sorted Lists(easy)

    Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...

  9. LightOJ1336 Sigma Function(约数和为偶数的个数)

    Sigma Function Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit ...

  10. Linux内核补丁升级

    如果机器已经联网,直接利用包管理工具更新,需要注意的是现在3.0以上的内核引入了签名机制,需要导入签名的key,参考步骤如下: 1.导入keyrpm --import https://www.elre ...