当前位置: 首页 > news >正文

A. Make All Equal

time limit per test

1 second

memory limit per test

256 megabytes

You are given a cyclic array a1,a2,…,ana1,a2,…,an.

You can perform the following operation on aa at most n−1n−1 times:

  • Let mm be the current size of aa, you can choose any two adjacent elements where the previous one is no greater than the latter one (In particular, amam and a1a1 are adjacent and amam is the previous one), and delete exactly one of them. In other words, choose an integer ii (1≤i≤m1≤i≤m) where ai≤a(imodm)+1ai≤a(imodm)+1 holds, and delete exactly one of aiai or a(imodm)+1a(imodm)+1 from aa.

Your goal is to find the minimum number of operations needed to make all elements in aa equal.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤5001≤t≤500). The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤1001≤n≤100) — the length of the array aa.

The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤n1≤ai≤n) — the elements of array aa.

Output

For each test case, output a single line containing an integer: the minimum number of operations needed to make all elements in aa equal.

Example

Input

Copy

 

7

1

1

3

1 2 3

3

1 2 2

5

5 4 3 2 1

6

1 1 2 2 3 3

8

8 7 6 3 8 7 6 3

6

1 1 4 5 1 4

Output

Copy

0
2
1
4
4
6
3

Note

In the first test case, there is only one element in aa, so we can't do any operation.

In the second test case, we can perform the following operations to make all elements in aa equal:

  • choose i=2i=2, delete a3a3, then aa would become [1,2][1,2].
  • choose i=1i=1, delete a1a1, then aa would become [2][2].

It can be proven that we can't make all elements in aa equal using fewer than 22 operations, so the answer is 22.

解题说明:水题,统计数列中那个数字出现的次数最多,删除其他数字就是答案。可以用数组来记录每个数字出现的次数,找出最大值再用总次数相减即可。

#include<stdio.h>int main()
{int t;scanf("%d", &t);while (t--){int n, m = 0;scanf("%d", &n);int a[101];for (int i = 0; i < n; i++){a[i] = 0;}for (int i = 0; i < n; i++){int x;scanf("%d", &x);a[x - 1]++;if (a[x - 1] > m){m = a[x - 1];}}printf("%d\n", n - m);}return 0;
}

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 【C++】C++ STL探索:Priority Queue与仿函数的深入解析
  • Winform管道模拟实现
  • 如何创建模板提示prompt
  • Node-RED和物联网分析:实时数据处理和可视化平台
  • Go协程及并发锁应用指南
  • Winform自定义控件和用户控件
  • 大数据新视界 --大数据大厂之算法在大数据中的核心作用:提升效率与智能决策
  • 大模型团队招人(校招):阿里巴巴智能信息,2025届春招来了!
  • 网站建设的服务器该如何选择?
  • 八股文-多线程、并发
  • 二层、三层网络基本原理
  • (c语言+数据结构链表)项目:贪吃蛇
  • 【QT基础】创建项目项目代码解释
  • 如何在GitHub上克隆仓库:HTTPS、SSH和GitHub CLI的区别
  • 即插即用!高德西交的PriorDrive:统一的矢量先验地图编码,辅助无图自动驾驶
  • 3.7、@ResponseBody 和 @RestController
  • Android开发 - 掌握ConstraintLayout(四)创建基本约束
  • gulp 教程
  • If…else
  • IIS 10 PHP CGI 设置 PHP_INI_SCAN_DIR
  • JavaScript 无符号位移运算符 三个大于号 的使用方法
  • Java超时控制的实现
  • Linux链接文件
  • Mybatis初体验
  • ng6--错误信息小结(持续更新)
  • PHP 程序员也能做的 Java 开发 30分钟使用 netty 轻松打造一个高性能 websocket 服务...
  • Python 基础起步 (十) 什么叫函数?
  • vue从创建到完整的饿了么(11)组件的使用(svg图标及watch的简单使用)
  • 个人博客开发系列:评论功能之GitHub账号OAuth授权
  • 嵌入式文件系统
  • 使用 Docker 部署 Spring Boot项目
  • 手写一个CommonJS打包工具(一)
  • 通过npm或yarn自动生成vue组件
  • 由插件封装引出的一丢丢思考
  • 最近的计划
  • 看到一个关于网页设计的文章分享过来!大家看看!
  • $con= MySQL有关填空题_2015年计算机二级考试《MySQL》提高练习题(10)
  • $refs 、$nextTic、动态组件、name的使用
  • (14)目标检测_SSD训练代码基于pytorch搭建代码
  • (2.2w字)前端单元测试之Jest详解篇
  • (2021|NIPS,扩散,无条件分数估计,条件分数估计)无分类器引导扩散
  • (MIT博士)林达华老师-概率模型与计算机视觉”
  • (poj1.3.2)1791(构造法模拟)
  • (博弈 sg入门)kiki's game -- hdu -- 2147
  • (超简单)使用vuepress搭建自己的博客并部署到github pages上
  • (过滤器)Filter和(监听器)listener
  • (六)DockerCompose安装与配置
  • (三十)Flask之wtforms库【剖析源码上篇】
  • (转)VC++中ondraw在什么时候调用的
  • (转载)Google Chrome调试JS
  • (转载)跟我一起学习VIM - The Life Changing Editor
  • .NET Core日志内容详解,详解不同日志级别的区别和有关日志记录的实用工具和第三方库详解与示例
  • .NET 动态调用WebService + WSE + UsernameToken
  • .net反编译工具
  • .stream().map与.stream().flatMap的使用