首页 > 其他分享 >Sakurako‘s Field Trip

Sakurako‘s Field Trip

时间:2024-10-27 15:19:17浏览次数:7  
标签:le Field int Sakurako disturbance students line include Trip

Sakurako’s Field Trip

Even in university, students need to relax. That is why Sakurakos teacher decided to go on a field trip. It is known that all of the students will be walking in one line. The student with index i i i has some topic of interest which is described as a i a_i ai​. As a teacher, you want to minimise the disturbance of the line of students.

The disturbance of the line is defined as the number of neighbouring people with the same topic of interest. In other words, disturbance is the number of indices j j j ( 1 ≤ j < n 1 \le j < n 1≤j<n) such that a j = a j + 1 a_j = a_{j + 1} aj​=aj+1​.

In order to do this, you can choose index i i i ( 1 ≤ i ≤ n 1\le i\le n 1≤i≤n) and swap students at positions i i i and n − i + 1 n-i+1 n−i+1. You can perform any number of swaps.

Your task is to determine the minimal amount of disturbance that you can achieve by doing the operation described above any number of times.

Input

The first line contains one integer t t t ( 1 ≤ t ≤ 1 0 4 1\le t\le 10^4 1≤t≤104) — the number of test cases.

Each test case is described by two lines.

  • The first line contains one integer n n n ( 2 ≤ n ≤ 1 0 5 2 \le n \le 10^5 2≤n≤105) — the length of the line of students.
  • The second line contains n n n integers a i a_i ai​ ( 1 ≤ a i ≤ n 1\le a_i\le n 1≤ai​≤n) — the topics of interest of students in line.

It is guaranteed that the sum of n n n across all test cases does not exceed 2 ⋅ 1 0 5 2\cdot 10^5 2⋅105.

Output

For each test case, output the minimal possible disturbance of the line that you can achieve.

Example

Input

9
5
1 1 1 2 3
6
2 1 2 2 1 1
4
1 2 1 1
6
2 1 1 2 2 4
4
2 1 2 3
6
1 2 2 1 2 1
5
4 5 5 1 5
7
1 4 3 5 1 1 3
7
3 1 3 2 2 3 3

Output

1
2
1
0
0
1
1
0
2

code

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#define int long long
 
using namespace std;
 
const int N = 2e5+10,INF=0x3f3f3f3f,mod=1e9+7;
 
typedef pair<int,int> PII;

int T;
int a[N];
int b[N];

void solve(){
	int n;
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=2,j=n-1;i<j;i++,j--){
		if(a[i]==a[i-1] || a[j]==a[j+1]) swap(a[i],a[j]);
	}
	for(int i=1;i<=n-1;i++){
		if(a[i]==a[i+1]){
			ans++;
		}
	}

	cout<<ans<<endl;
}
 
signed main(){
	cin>>T;
	while(T--){
		solve();
	}
	return 0;
}

标签:le,Field,int,Sakurako,disturbance,students,line,include,Trip
From: https://blog.csdn.net/2303_79062963/article/details/143250453

相关文章

  • 点跟踪论文—RAFT: Recurrent All-Pairs Field Transforms for Optical Flow-递归的全
    点目标跟踪论文—RAFT:RecurrentAll-PairsFieldTransformsforOpticalFlow-递归的全对场光流变换读论文RAFT密集光流跟踪的笔记RAFT是一种新的光流深度网络结构,由于需要基于点去做目标的跟踪,因此也是阅读了像素级别跟踪的一篇ECCV2020的经典论文——RAFT,递归的......
  • CF605E Intergalaxy Trips 与 对期望的进一步理解
    简化题面给一张无向图,在每一时刻,每一条边权值都为\(1\),出现的概率都是给定的(但不完全相同),问最优决策下\(1\)到\(n\)的期望。Attention:是每条边都会有概率出现,而不是走每条边都会有概率成功,这就意味着,我在某一点的不同的边的出现的情况下,我会做出选择。#sol.定义......
  • G. Sakurako and Chefir
    G.SakurakoandChefirGivenatreewith$n$verticesrootedatvertex$1$.WhilewalkingthroughitwithhercatChefir,Sakurakogotdistracted,andChefirranaway.TohelpSakurako,Kosukerecordedhis$q$guesses.Inthe$i$-thguess,heassumesthat......
  • PbootCMS附件上传报错UNKNOW: Code: 8192; Desc: stripos()
    错误分析:错误信息 UNKNOW:Code:8192;Desc:stripos() 表明在调用 stripos 函数时出现了问题。Code:8192 通常表示PHP的E_DEPRECATED警告,意味着某个函数或功能已被弃用,但仍可使用。修改建议:根据你的描述,需要修改 /core/function/file.php 文件中的 stri......
  • PbootCMS附件上传失败报错UNKNOW: Code: 8192; Desc: stripos():
    问题描述在使用PBootCMS上传附件时,如果遇到错误 UNKNOW:Code:8192;Desc:stripos(),这通常是由于PHP版本或配置问题导致的。stripos() 函数在某些PHP版本中可能会引发警告或错误。解决步骤检查PHP版本确认当前使用的PHP版本是否与PBootCMS兼容。PBootCMS通常支持PHP5.......
  • PbootCMS附件上传失败报错UNKNOW: Code: 8192; Desc: stripos(): Non-string needles
    PbootCMS附件上传失败报错“UNKNOW:Code:8192;Desc:stripos():Non-stringneedleswillbeinterpretedasstringsinthefuture.”是由于PHP版本更新导致的兼容性问题。具体来说,stripos()函数在处理非字符串类型的第二个参数(即needle)时,未来版本的PHP将会将其视为字符串,而......
  • Hopfield 神经网络中能量函数的含义及其变化值 ΔE≤0 的证明
    Hopfield神经网络中能量函数的含义及其变化值\(\DeltaE\leq0\)的证明Ciallo~(∠・ω<)⌒★我是赤川鹤鸣,本期是学习Hopfield神经网络时,遇到能量函数的相关知识时的思考和总结,希望有能帮助到你.Hopfield神经网络中,能量函数的定义如下\[E=-\dfrac{1}{2}\sum_{i......
  • Go语言中http.Transport的RoundTrip方法请求过滤与拦截技巧与应用
    go语言中http.transport的请求过滤与拦截技巧与应用1.引言在Go语言的http包中,http.Transport作为底层的HTTP传输层实现,提供了强大的功能,可以用于发起HTTP请求。本文将重点介绍如何使用http.Transport实现请求过滤和拦截的技巧及其应用。2.请求过滤2.1过滤请求方法我们可以使用h......
  • 星海智算:史上最大争议!AI先驱Hinton与Hopfield斩获诺贝尔物理学奖
    AI新闻资讯 近两日,两位机器学习先驱 JohnJ.Hopfield和GeoffreyE.Hinton 获得了2024诺贝尔物理学奖,这一消息引爆了整个AI领域!史上最大争议!AI先驱Hinton与Hopfield斩获诺贝尔物理学奖10月8日,瑞典皇家科学院宣布,2024年度诺贝尔物理学奖授予美国科学家约翰·霍......
  • go gorm StructField动态生成结构体查询单条表记录
    funcTest014_TakeTableFields(t*testing.T){vardbRequest=Default().SetPageSize(2)dbRequest.TableName="sys_dept"dbRequest.FieldsName="dept_id,dept_name"varresult=dbRequest.GeneralTakeTable()golog.Info......