A. Desorting

devtools/2024/9/22 18:25:57/

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Call an array a𝑎 of length n𝑛 sorted if a1≤a2≤…≤an−1≤an𝑎1≤𝑎2≤…≤𝑎𝑛−1≤𝑎𝑛.

Ntarsis has an array a𝑎 of length n𝑛.

He is allowed to perform one type of operation on it (zero or more times):

  • Choose an index i𝑖 (1≤i≤n−11≤𝑖≤𝑛−1).
  • Add 11 to a1,a2,…,ai𝑎1,𝑎2,…,𝑎𝑖.
  • Subtract 11 from ai+1,ai+2,…,an𝑎𝑖+1,𝑎𝑖+2,…,𝑎𝑛.

The values of a𝑎 can be negative after an operation.

Determine the minimum operations needed to make a𝑎 not sorted.

Input

Each test contains multiple test cases. The first line contains the number of test cases t𝑡 (1≤t≤1001≤𝑡≤100). The description of the test cases follows.

The first line of each test case contains a single integer n𝑛 (2≤n≤5002≤𝑛≤500) — the length of the array a𝑎.

The next line contains n𝑛 integers a1,a2,…,an𝑎1,𝑎2,…,𝑎𝑛 (1≤ai≤1091≤𝑎𝑖≤109) — the values of array a𝑎.

It is guaranteed that the sum of n𝑛 across all test cases does not exceed 500500.

Output

Output the minimum number of operations needed to make the array not sorted.

Example

input

Copy

 

4

2

1 1

4

1 8 10 13

3

1 3 2

3

1 9 14

output

Copy

1
2
0
3

Note

In the first case, we can perform 11 operation to make the array not sorted:

  • Pick i=1𝑖=1. The array a𝑎 then becomes [2,0][2,0], which is not sorted.

In the second case, we can perform 22 operations to make the array not sorted:

  • Pick i=3𝑖=3. The array a𝑎 then becomes [2,9,11,12][2,9,11,12].
  • Pick i=3𝑖=3. The array a𝑎 then becomes [3,10,12,11][3,10,12,11], which is not sorted.

It can be proven that 11 and 22 operations are the minimal numbers of operations in the first and second test cases, respectively.

In the third case, the array is already not sorted, so we perform 00 operations.

解题说明:此题是让数列不要递增,然后找到最少的次数,比较容易想到找出数列中前后差值最小的情况,然后改变这前后一对数即可。


#include<stdio.h>
int main()
{int n;scanf("%d", &n);while (n--) {int m, a[500], min = 1000000000;scanf("%d", &m);scanf("%d", &a[0]);for (int i = 1; i < m; i++){scanf("%d", &a[i]);min = (min < a[i] - a[i - 1]) ? min :( a[i] - a[i - 1]);}if (min < 0){printf("0");}else if (min == 0){printf("1");}else{printf("%d", min / 2 + 1);}printf("\n");}return 0;
}


http://www.ppmy.cn/devtools/20103.html

相关文章

清华大学 【战略管理的逻辑】全6讲笔记

讨论从20世纪初的企业管理背景入手&#xff0c;讲述了随着经济和技术的进步&#xff0c;企业管理理念和实践所经历的主要变化。 1.战略管理的重要性及其时代演变 在过去的几十年里&#xff0c;企业管理的理念和方法经历了从重视生产效率到注重市场营销&#xff0c;再到强调战略…

FPGA 多路分频器实现

在 FPGA 中&#xff0c;时钟分频是经常用到的。本节实现 2 分频、 3 分频、 4 分频和 8 分频的 Verilog 实现&#xff0c;以及仿真调试。 仿真步骤不是必须的&#xff0c;但是仿真可以发现很多我们设计的错误或者隐患问题&#xff0c;进而对设计进行调整。 FPGA 输入…

大语言模型在研究领域的应用——信息检索中的大语言模型

信息检索中的大语言模型 大语言模型提升信息检索任务利用大语言模型进行信息检索大语言模型增强的信息检索模型. 检索增强的大语言模型输入优化策略.指令微调策略.预训练策略. 总结应用建议未来方向 大语言模型对于传统信息检索技术与应用范式带来了重要影响。这两者在技术路径…

巴西游戏市场海外营销洞察

巴西作为南美洲最大的国家&#xff0c;近年来在游戏产业领域取得了显著的发展&#xff0c;2023年巴西整体移动游戏市场收入规模超60亿元&#xff0c;显示出强劲的市场活力。巴西游戏市场以其庞大的用户基础&#xff0c;不断增长的消费能力以及日益完善的产业环境&#xff0c;吸…

LeetCode93:复原IP地址

题目描述 有效 IP 地址 正好由四个整数&#xff08;每个整数位于 0 到 255 之间组成&#xff0c;且不能含有前导 0&#xff09;&#xff0c;整数之间用 ‘.’ 分隔。 例如&#xff1a;“0.1.2.201” 和 “192.168.1.1” 是 有效 IP 地址&#xff0c;但是 “0.011.255.245”、“…

PDF加密了无法编辑?解密方法来了!

一下午都在捣鼓各种格式问题&#xff0c;首先是需要合并几个 PDF&#xff0c;然而有一个文件加密了无法操作&#xff0c;碰到加密不能编辑就很头痛&#xff0c;终于让我找到一个可行的方法了&#xff0c; 首先就这个加密文件右键选择打开方式-Google Chrome>>打开>>…

(救命)Kali Linux或者其他linux系统的触控板右键按下没反应,失效的解决办法

我每次安装kali的时候都会选择gnome桌面&#xff0c;每次安装好右键都是禁用的&#xff0c;按下和左键效果一样&#xff0c;每次都得去调鼠标右键&#xff0c;原来就不好找到那个选项&#xff0c;这次踏马居然连那个选项都没了&#xff0c;如果你去网上找教程你会发现网上根本没…

汽车新四化,会发生什么?

北京国际汽车展览会正如火如荼地进行中,作为国内外汽车行业瞩目的盛会&#xff0c;众多车企纷纷亮出了自家的“杀手锏”。 这场汽车的盛宴不仅集中展示了众多汽车品牌的最新技术和产品&#xff0c;更深刻体现了汽车新四化的发展趋势。汽车新四化&#xff0c;即电动化、网联化、…