题目
题意:
给你一个序列,现在这个序列中可以将相邻的不同的元素相加,可以重复若干次,问最后的会剩下几个元素。
思路:
除非全部相等的话,答案是 n n n,否则都是 1 1 1,因为只要有两个元素是不同的,肯定可以全部消除,比如 A = B + C A=B+C A=B+C,那么我们就可以将 A + B A+B A+B,这样 a n s = 1 ans=1 ans=1。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <cctype>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <class T>
inline void read(T &ret) {
char c;
int sgn;
if (c = getchar(), c == EOF) return ;
while (c != '-' && (c < '0' || c > '9')) c = getchar();
sgn = (c == '-') ? -1:1;
ret = (c == '-') ? 0:(c - '0');
while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
ret *= sgn;
return ;
}
inline void outi(int x) {if (x > 9) outi(x / 10);putchar(x % 10 + '0');}
inline void outl(ll x) {if (x > 9) outl(x / 10);putchar(x % 10 + '0');}
int a[200010];
int main() {
int t; read(t); while (t--) {
int n; read(n);
for (int i = 0; i < n; i++) read(a[i]);
bool book = false;
for (int i = 0; i < n - 1; i++) {
if (a[i] != a[i + 1]) {
book = true;
break;
}
}
if (book) cout << "1\n";
else cout << n << endl;
}
return 0;
}