题意:给你含有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. java去除字符串中的空格、回车、换行符、制表符

    import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @author chzeze * 2016-11-07 */ ...

  2. ext 对齐

    layout : { type : 'hbox', pack : 'end' } buttonAlign:'center', //按钮居中   pack : String Controls how t ...

  3. 【GoLang】GoLang 错误处理 -- 官方推荐方式 示例

    最严谨的方式,Always检查error,并做相应的处理 项目结构: 代码: common.go: package common import ( "github.com/pkg/error ...

  4. 流程图制作在云上 https://www.processon.com/

    流程图制作在云上 : https://www.processon.com/

  5. 【Unity3D】计算二维向量夹角(-180到180)

    在Unity3D中,有时候我们需要计算二维向量的夹角.二维向量夹角一般在0~180度之前,可以直接调用Vector2.Angle(Vector2 from, Vector2 to)来计算. 但是在有些 ...

  6. Python之多线程

    廖雪峰教程--- http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/00138683 ...

  7. MySQL 利用SQL线程对Binlog操作

    背景: 对于MySQL的binlog的查看都是用其自带的工具mysqlbinlog进行操作的,其实还有另一个方法来操作binlog,就是Replication中的SQL线程去操作binlog,其实bi ...

  8. Velocity 基本语法

    Velocity 基本语法 Velocity 是一个基于 Java 的模板引擎框架,提供的模板语言可以使用在 Java 中定义的对象和变量上.Velocity 是 Apache 基金会的项目,开发的目 ...

  9. 【leetcode】Binary Tree Preorder Traversal (middle)★

    Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binary tr ...

  10. 【processing】小代码4

    translate(x,y);  移动坐标原点到x,y处 rotate(angle); 坐标沿原点顺时针转动angle度 scale(n); 绘制图像放大n倍 pushMatrix() 将当前坐标压入 ...