题解 P11231【[CSP-S 2024] 决斗】
题目描述
今天是小 Q 的生日,他得到了
一场游戏分为若干回合。每回合,小 Q 会选择某只怪兽
小 Q 希望决定一组攻击顺序,使得在游戏结束时,未退出游戏的怪兽数量尽可能少。
对于所有测试数据,保证:
solution
可以优先将
code
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) fprintf(stderr, ##__VA_ARGS__)
#else
#define debug(...) void(0)
#define endl "\n"
#endif
using LL = long long;
int n, a[100010];
int main() {
#ifndef LOCAL
#ifdef NF
freopen("duel.in", "r", stdin);
freopen("duel.out", "w", stdout);
#endif
cin.tie(nullptr)->sync_with_stdio(false);
#endif
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
int ans = 0;
for (int i = 1, j = 2; max(i, j) <= n; i++) {
while (j <= n && a[j] <= a[i]) ++j;
if (j <= n) ++ans, ++j;
}
cout << n - ans << endl;
return 0;
}
本文来自博客园,作者:caijianhong,转载请注明原文链接:https://www.cnblogs.com/caijianhong/p/18526008/solution-P11231
分类:
solution
标签:
greedy
, two pointers
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】