codeforces A. Omkar and Password

在这里插入图片描述

题目

题意:

给你一个序列,现在这个序列中可以将相邻的不同的元素相加,可以重复若干次,问最后的会剩下几个元素。

思路:

除非全部相等的话,答案是 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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值