Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) B Box
Posted qingyuyyyyy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) B Box相关的知识,希望对你有一定的参考价值。
#include<bits/stdc++.h> using namespace std; int shu[100005]; int ans[100005]; int main() { int total; cin>>total; while(total--) { int n; bool flag=true; cin>>n; unordered_set<int>tree; set<int>num; for(int i=1; i<=n; i++) num.insert(i);//插入每个数字 从小到大 for(int i=1; i<=n; i++) cin>>shu[i];//记录每个数字 for(int i=1; i<=n; i++) { if(tree.find(shu[i])==tree.end()) {//如果当前位置的最大值没有出现过,那么该最大值在此位置第一次出现 tree.insert(shu[i]);//插入 num.erase(shu[i]);//删除 ans[i]=shu[i];//记录 } else//如果当前位置的最大值出现过 ,就从小于该最大值的数字中随便选一个没用的 { for(auto j=num.begin(); j!=num.end(); j++) { if((*j)<shu[i])// 如果有 { ans[i]=(*j);//加进去 num.erase(j);//删掉 break;//推出循环 } else if(*j>shu[i]) {//如果最小的都大于, flag=false; break; } } if(!flag) break; } } if(!flag) cout<<-1<<endl; else { for(int i=1; i<=n; i++) { cout<<ans[i]<<" "; } cout<<endl; } } return 0; }
以上是关于Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) B Box的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) B. Box 贪心
Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) B Box
Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3)
Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) C. Messy 构造
Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) C Messy
Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3