题解归档 - cf2220A

题解归档 - cf2220A

本文由 cf-code 本地题解库自动归档;公开内容以本地 AC/验证版本为准。

思路

cf2220A - Blocked

Pattern

All numbers are positive. If two equal values exist, whichever copy appears
later is blocked by the earlier equal copy, so the answer is impossible.

If all values are distinct, sort them in decreasing order. For any position,
all previous values are strictly larger than the current value, and every
non-empty subset sum of previous values is therefore larger than the current
value. Hence no position is blocked.

Algorithm

  • If any duplicate exists, print -1.
  • Otherwise print the array in descending order.

Checks

  • python tools/math_reasoning_search.py --problem cf2220A -n 5 - required
    precheck done.

代码

来源:problems/cf2220A/solution.cpp

/* Author: likely
 * Time: 2026-06-08 00:05:00
**/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll s[205],cnt[105];
int main(){
    ll t,n,i,zc;
    cin>>t;
    while(t--){
        cin>>n;
        zc=0;
        for(i=1;i<=100;i++) cnt[i]=0;
        for(i=1;i<=n;i++){
            cin>>s[i];
            if(cnt[s[i]]) zc=1;
            cnt[s[i]]++;
        }
        if(zc){
            cout<<"-1\n";
            continue;
        }
        sort(s+1,s+n+1,greater<ll>());
        for(i=1;i<=n;i++){
            if(i>1) cout<<" ";
            cout<<s[i];
        }
        cout<<"\n";
    }
    return 0;
}
~  ~  The   End  ~  ~


 赏 
感谢您的支持,我会继续努力哒!
支付宝收款码
tips
文章二维码 分类标签:归档TypechoAutoUpload
文章标题:题解归档 - cf2220A
文章链接:https://www.fangshaonian.cn/archives/211/
最后编辑:2026 年 6 月 28 日 19:04 By 方少年
许可协议: 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
(*) 6 + 7 =
快来做第一个评论的人吧~