跳到正文

个人记录

【三月份 -- 基础语法组】-- T2 --游戏 game

zhangyuqiTAT约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年4月12日
收录
2025年12月12日
更新
2026年11月21日
篇幅
约 2 分钟

版本

  1. v1当前

网址: https://cspjs.online/contest/660/problem/2

题解: https://b1bznc26af6.feishu.cn/file/EGvfbzAGno8mvYxG0JJcLcIgn9d?from=from_copylink

C++
#include <bits/stdc++.h>
using namespace std;
long long minn = -1;
int num[10100];
int main() {
    freopen("game.in", "r", stdin);
    freopen("game.out", "w", stdout);
    std::ios::sync_with_stdio(false);
    int n, ans = 0, cnt = 1;
    cin >> n;
    memset(num, -1, sizeof(num));
    for (int i = 0; i < n; i++) {
        cin >> num[i];
    }
    sort(num, num + n);
    for (int i = 0; i < n; i++) {
        int a = num[i];
        if (num[i] != -1) {
            for (int j = 0; j < n; j++) {
                if (num[j] == a + 1) {
                    a = num[j];
                    num[j] = -1;
                    cnt++;
                }
            }
            if (cnt >= 2) {
                ans++;
                cnt = 1;
                num[i] = -1;
            }
        }
    }
    cout << ans;
    return 0;
}
原文