A. Omkar and Password

传送门
A. Omkar and Password
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Lord Omkar has permitted you to enter the Holy Church of Omkar! To test your worthiness, Omkar gives you a password which you must interpret!
A password is an array a of n positive integers. You apply the following operation to the array: pick any two adjacent numbers that are not equal to each other and replace them with their sum. Formally, choose an index i such that 1≤i<n and ai≠ai+1, delete both ai and ai+1 from the array and put ai+ai+1 in their place.
For example, for array [7,4,3,7]
you can choose i=2 and the array will become [7,4+3,7]=[7,7,7]
Note that in this array you can’t apply this operation anymore.
Notice that one operation will decrease the size of the password by 1
What is the shortest possible length of the password after some number (possibly 0) of operations?

Input
Each test contains multiple test cases. The first line contains the number of test cases t(1≤t≤100). Description of the test cases follows.The first line of each test case contains an integer n(1≤n≤2⋅105) — the length of the password.The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109) — the initial contents of your password.
The sum of n over all test cases will not exceed 2⋅105

Output
For each password, print one integer: the shortest possible length of the password after some number of operations.

Example
Input

2
4
2 1 3 1
2
420 420

Output

1
2

Note
In the first test case, you can do the following to achieve a length of 1
Pick i=2to get [2,4,1]
Pick i=1to get [6,1]
Pick i=1to get [7]
In the second test case, you can’t perform any operations because there is no valid i that satisfies the requirements mentioned above.

题意:给你一个n大小的数组,每次可以合并俩个不同的数,问最后你能把数组压缩到的最小长度是多少?答案只有1 或者 n。

思路:这题思路很简单,答案只有1或者n.输入的数组里面只要有一个数字不同就是输出1,输入的数字全部相同就是n。

AC代码

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int t,n,a[200005],flag;
	cin>>t;
	while(t--)
	{
		flag=0;
		cin>>n;
		cin>>a[1];
		for(int i=2;i<=n;i++)
		{
			cin>>a[i];
			if(a[i]!=a[i-1]) 
				flag=1;
		}
		if(flag==1)
			cout<<"1"<<endl;
		else
			cout<<n<<endl;
	} return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

稚皓君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值