Codeforce 1255 Round #601 (Div. 2) C. League of Leesins (大模拟)
Bob is an avid fan of the video game "League of Leesins", and today he celebrates as the League of Leesins World Championship comes to an end!
The tournament consisted of nn (n≥5n≥5) teams around the world. Before the tournament starts, Bob has made a prediction of the rankings of each team, from 11-st to nn-th. After the final, he compared the prediction with the actual result and found out that the ii-th team according to his prediction ended up at the pipi-th position (1≤pi≤n1≤pi≤n, all pipi are unique). In other words, pp is a permutation of 1,2,…,n1,2,…,n.
As Bob's favorite League player is the famous "3ga", he decided to write down every 33 consecutive elements of the permutation pp. Formally, Bob created an array qq of n−2n−2 triples, where qi=(pi,pi+1,pi+2)qi=(pi,pi+1,pi+2) for each 1≤i≤n−21≤i≤n−2. Bob was very proud of his array, so he showed it to his friend Alice.
After learning of Bob's array, Alice declared that she could retrieve the permutation pp even if Bob rearranges the elements of qq and the elements within each triple. Of course, Bob did not believe in such magic, so he did just the same as above to see Alice's respond.
For example, if n=5n=5 and p=[1,4,2,3,5]p=[1,4,2,3,5], then the original array qq will be [(1,4,2),(4,2,3),(2,3,5)][(1,4,2),(4,2,3),(2,3,5)]. Bob can then rearrange the numbers within each triple and the positions of the triples to get [(4,3,2),(2,3,5),(4,1,2)][(4,3,2),(2,3,5),(4,1,2)]. Note that [(1,4,2),(4,2,2),(3,3,5)][(1,4,2),(4,2,2),(3,3,5)] is not a valid rearrangement of qq, as Bob is not allowed to swap numbers belong to different triples.
As Alice's friend, you know for sure that Alice was just trying to show off, so you decided to save her some face by giving her any permutation pp that is consistent with the array qq she was given.
Input
The first line contains a single integer nn (5≤n≤1055≤n≤105) — the size of permutation pp.
The ii-th of the next n−2n−2 lines contains 33 integers qi,1qi,1, qi,2qi,2, qi,3qi,3 (1≤qi,j≤n1≤qi,j≤n) — the elements of the ii-th triple of the rearranged (shuffled) array qiqi, in random order. Remember, that the numbers within each triple can be rearranged and also the positions of the triples can be rearranged.
It is guaranteed that there is at least one permutation pp that is consistent with the input.
Output
Print nn distinct integers p1,p2,…,pnp1,p2,…,pn (1≤pi≤n1≤pi≤n) such that pp is consistent with array qq.
If there are multiple answers, print any.
Example
Input
5
4 3 2
2 3 5
4 1 2
Output
1 4 2 3 5
这个题,出现次数最少的在两边,确定了第一个为出现次数 1 2 3的那一组,然后根据那一组暴力即可,用STL优化了一下,不然会超时。
#include<bits/stdc++.h>
using namespace std;
int a[100000],b[100000],c[100000],vis[1000000],n;
vector<int> v[1000000];
int main()
{
cin>>n;
for(int i=0;i<n-2;++i)
{
cin>>a[i]>>b[i]>>c[i];
v[a[i]-1].push_back(i);
v[b[i]-1].push_back(i);
v[c[i]-1].push_back(i);
vis[a[i]-1]=1;
vis[b[i]-1]=1;
vis[c[i]-1]=1;
}
int x=0;
for(;v[x].size()!=1;++x);
vis[x]=0;
cout<<x+1<<" ";
int y,z;
if(v[a[v[x][0]]-1].size()==2)
{
y=a[v[x][0]]-1;
vis[y]=0;
}
else if(v[a[v[x][0]]-1].size()==3)
{
z=a[v[x][0]]-1;
vis[z]=0;
}
if(v[b[v[x][0]]-1].size()==2)
{
y=b[v[x][0]]-1;
vis[y]=0;
}
else if(v[b[v[x][0]]-1].size()==3)
{
z=b[v[x][0]]-1;
vis[z]=0; }
if(v[c[v[x][0]]-1].size()==2)
{
y=c[v[x][0]]-1;
vis[y]=0;
}
else if(v[c[v[x][0]]-1].size()==3)
{
z=c[v[x][0]]-1;
vis[z]=0;
}
cout<<y+1<<" "<<z+1<<" ";
int h=z;
int cnt=3;
while(cnt++<n)
{
for(int i=0;i<v[h].size();++i)
{
if(vis[a[v[h][i]]-1]+vis[b[v[h][i]]-1]+vis[c[v[h][i]]-1]==1)
{
if(vis[a[v[h][i]]-1]==1){
cout<<a[v[h][i]]<<" ";
vis[a[v[h][i]]-1]=0;
h=a[v[h][i]]-1;
}
else if(vis[b[v[h][i]]-1]==1){
cout<<b[v[h][i]]<<" ";
vis[b[v[h][i]]-1]=0;
h=b[v[h][i]]-1;
}
else if(vis[c[v[h][i]]-1]==1){
cout<<c[v[h][i]]<<" ";
vis[c[v[h][i]]-1]=0;
h=c[v[h][i]]-1;
}
break;
}
}
}
}
Codeforce 1255 Round #601 (Div. 2) C. League of Leesins (大模拟)的更多相关文章
- Codeforce 1255 Round #601 (Div. 2)D. Feeding Chicken (模拟)
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he deci ...
- Codeforce 1255 Round #601 (Div. 2)B. Fridge Lockers(思维)
Hanh lives in a shared apartment. There are nn people (including Hanh) living there, each has a priv ...
- Codeforce 1255 Round #601 (Div. 2) A. Changing Volume (贪心)
Bob watches TV every day. He always sets the volume of his TV to bb. However, today he is angry to f ...
- Codeforces Round #601 (Div. 2) C League of Leesins
把每一次输入的一组数字存下来,然后把每个数字出现的组数存下来 然后找只出现过一次的数字a,那么这个数字a不是开头就是结尾,默认为开头(是哪个都无所谓),然后去找和它出现在同一组的两个数字b和c,而b和 ...
- 【cf比赛记录】Codeforces Round #601 (Div. 2)
Codeforces Round #601 (Div. 2) ---- 比赛传送门 周二晚因为身体不适鸽了,补题补题 A // http://codeforces.com/contest/1255/p ...
- Codeforces Round #601 (Div. 2)
传送门 A. Changing Volume 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/19 22:37:33 */ #include ...
- codeforce Codeforces Round #201 (Div. 2)
cf 上的一道好题: 首先发现能生成所有数字-N 判断奇偶 就行了,但想不出来,如何生成所有数字,解题报告 说是 所有数字的中最大的那个数/所有数字的最小公倍数,好像有道理:纪念纪念: #incl ...
- CodeForce edu round 53 Div 2. D:Berland Fair
D. Berland Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version)
Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version) N个盒子,每个盒子有a[i]块巧克力,每次操作可以将盒子中的 ...
随机推荐
- 家庭记账本app进度之复选框以及相应滚动条的应用
这次主要是对于android中复选框的相应的操作.以及其中可能应用到的滚动条的相关应用.每一个复选框按钮都要有一个checkBox与之相对应. 推荐使用XML配置,基本语法如下:<CheckBo ...
- go语言goroutine
Go语言goroutine 在别的语言里想要在一个程序中实现多任务,如python,python实现多任务可以使用多进程.多线程.携程.但多进程占用资源,多线程无法发挥多核的优势(GIL),pytho ...
- Unity Shader and Effects Cookbook问题记录
1.p61的specular计算,涉及到的一个参数“_SpecColor”是在Unity的官方cginc文件(UnityLightingCommon.cginc)中,是直接赋颜色给这个参数,反应到你模 ...
- CVPR2020文章汇总 | 点云处理、三维重建、姿态估计、SLAM、3D数据集等(12篇)
作者:Tom Hardy Date:2020-04-15 来源:CVPR2020文章汇总 | 点云处理.三维重建.姿态估计.SLAM.3D数据集等(12篇) 1.PVN3D: A Deep Point ...
- TP字段加一操作
经常有需要对某个数据表的计数字段进行加减操作,我们来看下在ThinkPHP中的具体使用办法.最简单的,使用下面方法对score自动加1: M('User')->where('id=5')-> ...
- python3(三十五)file read write
""" 文件读写 """ __author__on__ = 'shaozhiqi 2019/9/23' # !/usr/bin/env py ...
- Python中关于字符串你应该知道这些...
# Python中字符串的常见用法### 定义:带有双引号/单引号/三引号### 双引号:适用于所写的字符串里没有双引号的.例如:"凡是“辛苦”必是礼物"报错### 单引号:适用 ...
- 搭建WEB、NFS共享、sersync实时同步以及全网定时备份服务流程
本次实验的主要目的: 1.搭建web服务,使用nfs服务共享的/data目录挂载到web站点目录上. 2.nfs服务器与backup服务器使用sersync实时同步/data目录中的文件. 3.bac ...
- 10行代码,用python能做出什么骚操作
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:小栗子 PS:如有需要Python学习资料的小伙伴可以加点击下方链接自 ...
- 1324E - Sleeping Schedule
题目大意:一天有h个小时,一个人喜欢睡觉,一共睡n次,每次都睡h个小时,开始时间为0,间隔a[i]或a[i]-1个小时开始睡第i次觉,每天都有一个最好时间区间,问这n次觉,最多有多少次是在最好时间内睡 ...