CF471B MUH and Important Things
题目描述
It's time polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got down to business. In total, there are nn tasks for the day and each animal should do each of these tasks. For each task, they have evaluated its difficulty. Also animals decided to do the tasks in order of their difficulty. Unfortunately, some tasks can have the same difficulty, so the order in which one can perform the tasks may vary.
Menshykov, Uslada and Horace ask you to deal with this nuisance and come up with individual plans for each of them. The plan is a sequence describing the order in which an animal should do all the nn tasks. Besides, each of them wants to have its own unique plan. Therefore three plans must form three different sequences. You are to find the required plans, or otherwise deliver the sad news to them by stating that it is impossible to come up with three distinct plans for the given tasks.
输入格式
It's time polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got down to business. In total, there are nn tasks for the day and each animal should do each of these tasks. For each task, they have evaluated its difficulty. Also animals decided to do the tasks in order of their difficulty. Unfortunately, some tasks can have the same difficulty, so the order in which one can perform the tasks may vary.
Menshykov, Uslada and Horace ask you to deal with this nuisance and come up with individual plans for each of them. The plan is a sequence describing the order in which an animal should do all the nn tasks. Besides, each of them wants to have its own unique plan. Therefore three plans must form three different sequences. You are to find the required plans, or otherwise deliver the sad news to them by stating that it is impossible to come up with three distinct plans for the given tasks.
输出格式
In the first line print "YES" (without the quotes), if it is possible to come up with three distinct plans of doing the tasks. Otherwise print in the first line "NO" (without the quotes). If three desired plans do exist, print in the second line nn distinct integers that represent the numbers of the tasks in the order they are done according to the first plan. In the third and fourth line print two remaining plans in the same form.
If there are multiple possible answers, you can print any of them.
输入输出样例
输入 #1复制
输出 #1复制
输入 #2复制
输出 #2复制
说明/提示
It's time polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got down to business. In total, there are nn tasks for the day and each animal should do each of these tasks. For each task, they have evaluated its difficulty. Also animals decided to do the tasks in order of their difficulty. Unfortunately, some tasks can have the same difficulty, so the order in which one can perform the tasks may vary.
Menshykov, Uslada and Horace ask you to deal with this nuisance and come up with individual plans for each of them. The plan is a sequence describing the order in which an animal should do all the nn tasks. Besides, each of them wants to have its own unique plan. Therefore three plans must form three different sequences. You are to find the required plans, or otherwise deliver the sad news to them by stating that it is impossible to come up with three distinct plans for the given tasks.
题解:
题目大意:
在这道题的翻译还没挂上来之前,我就把它放到题解上了:
一些任务有着不同的困难度。但是可能会有一些任务的困难度相同。现在,两只北极熊和一只大象希望你能给出3种难度递增而且顺序不同的序列。如果存在的话,请输出YES和这三种不同的序列。否则输出NO。如果你完不成这个任务,它们仨就会吃了你,加油!
题目解析:
其实就是一道模拟。或者说把它叫做排序也好。随便你怎么说。
是这样:
因为是任意三个合法序列。所以我们只需要把相邻的两个相等元素交换一下位置即可。
那么显然地,如果有两个及两个以下的相等元素,那么是肯定不可以的。直接输出NO。否则就输出YES,并且交换任意一个相邻的相等元素。正着扫一遍,反着扫一遍即可。
代码:
#include<cstdio>
#include<algorithm>
using namespace std;
int n,cnt;
struct data
{
int v,pos;
}a[2005];
bool cmp(data a,data b)
{
return a.v<b.v;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i].v);
a[i].pos=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++)
if(a[i].v==a[i-1].v)
cnt++;
if(cnt<2)
{
puts("NO");
return 0;
}
else
{
puts("YES");
for(int i=1;i<=n;i++)
printf("%d ",a[i].pos);
puts("");
for(int i=1;i<=n;i++)
if(a[i].v==a[i-1].v)
{
swap(a[i],a[i-1]);
break;
}
for(int i=1;i<=n;i++)
printf("%d ",a[i].pos);
puts("");
for(int i=n;i;i--)
if(a[i].v==a[i-1].v)
{
swap(a[i],a[i-1]);
break;
}
for(int i=1;i<=n;i++)
printf("%d ",a[i].pos);
puts("");
}
return 0;
}