P10337 [UESTCPC 2024] 操作序列
题解
极端试探法,既然要求 k 的最大值,k 最大为 n,当 k 能取 n 是什么时候?是所有数都相等的时候。
k能不能取n-1?能,给n-1个数同时乘上一个数,等价于剩下的那个数除以一个数(相对大小),而把所有数都除到1,它们就相等了
举例:
2 3 4 5 给后面3个数同时乘上2 \(\to\) 2 6 8 10 相对大小等价于 \(\to\) 1 3 4 5 \(\to\) 第一个数除以二
code
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int flag=0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(i>1&&a[i]!=a[i-1]) flag=1;
}
if(flag) cout<<n-1<<endl;
else cout<<n<<endl;
}
return 0;
}

浙公网安备 33010602011771号