题解:CF2205C Simons and Posting Blogs
Little_Fox_Fairy · · 题解
根据身边统计学,机房同学有 eps 个人知道 vector 可以直接比较字典序大小。
思路是简单的,注意到后加的会放到前面去,不难想到将序列翻转之后排序。
但是这有问题,因为已经确定放在后面的数在前面的位置已经不重要了,所以要将已经确定好放在后面的数去掉再排序。
序列排序这个可以用 vector 简单实现,避免写得很丑陋。
参考代码:
void solve() {
cin>>n;
rep(i,1,n) {
cin>>len[i];
rep(j,1,len[i]) {
cin>>a[i][j];
if (!used[a[i][j]]) used[a[i][j]]=1,m++;
}
}
vector<int> res;
while (res.size()<m) {
vector<int> now;
int pos=0;
rep(i,1,n) if (!ans[i]) {
vector<int> tmp;
Rep(j,len[i],1) if (!vis[a[i][j]] and !vised[a[i][j]]) tmp.eb(a[i][j]),vised[a[i][j]]=1;
rep(j,1,len[i]) vised[a[i][j]]=0;
if (!tmp.size()) continue;
if (!now.size()) now=tmp,pos=i;
else if (tmp<now) now=tmp,pos=i;
}
ans[pos]=1;
for (auto x : now) if (!vis[x]) vis[x]=1,res.eb(x);
}
for (auto x : res) cout<<x<<" ";
cout<<endl;
return Clear();
}