codeforces471B
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 ntasks 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 n 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.
Input
The first line contains integer n (1 ≤ n ≤ 2000) — the number of tasks. The second line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 2000), where hi is the difficulty of the i-th task. The larger number hi is, the more difficult the i-th task is.
Output
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 ndistinct 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.
Examples
4
1 3 3 1
YES
1 4 2 3
4 1 2 3
4 1 3 2
5
2 4 1 4 8
NO
Note
In the first sample the difficulty of the tasks sets one limit: tasks 1 and 4 must be done before tasks 2 and 3. That gives the total of four possible sequences of doing tasks : [1, 4, 2, 3], [4, 1, 2, 3], [1, 4, 3, 2], [4, 1, 3, 2]. You can print any three of them in the answer.
In the second sample there are only two sequences of tasks that meet the conditions — [3, 1, 2, 4, 5] and [3, 1, 4, 2, 5]. Consequently, it is impossible to make three distinct sequences of tasks.
sol:XJB构造三串不同的字典序最小的序列,十分容易,两个相同的就两两交换,多个相同的就用第一个与第二个或第三个(最后一个)交换,这样就凑到三种情况了
Ps:可能构造多种会比较困难,感觉只会n!的方法(GG)
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,Hash[N];
struct data
{
int Shuz;
}a[N];
int Pailie[N];
int Used[N];
vector<int>Jih[N];
int main()
{
int i,j,Fas=;
R(n);
for(i=;i<=n;i++)
{
R(a[i].Shuz); Hash[++*Hash]=a[i].Shuz;
}
sort(Hash+,Hash+*Hash+);
*Hash=unique(Hash+,Hash+*Hash+)-Hash-;
for(i=;i<=n;i++)
{
a[i].Shuz=lower_bound(Hash+,Hash+*Hash+,a[i].Shuz)-Hash;
Jih[a[i].Shuz].push_back(i);
}
for(i=;i<=*Hash&&Fas<;i++)
{
if(Jih[i].size()==) Fas*=;
else if(Jih[i].size()>) Fas=;
}
if(Fas<) return *puts("NO");
puts("YES");
for(int Step=;Step<=;Step++)
{
bool Bo=;
for(i=;i<=*Hash;i++)
{
if(Bo)
{
Used[i]=;
for(j=;j<Jih[i].size();j++) W(Jih[i][j]);
continue;
}
if(Jih[i].size()==)
{
W(Jih[i][]); continue;
}
else if(Jih[i].size()==)
{
if(Used[i]==)
{
W(Jih[i][]); W(Jih[i][]); Bo=;
Used[i]++;
}
else if(Used[i]==)
{
W(Jih[i][]); W(Jih[i][]); Bo=;
Used[i]++;
}
else
{
W(Jih[i][]); W(Jih[i][]);
}
}
else
{
if(Used[i]==)
{
for(j=;j<Jih[i].size();j++) W(Jih[i][j]);
Bo=;
Used[i]++;
}
else if(Used[i]==)
{
W(Jih[i][]); W(Jih[i][]);
for(j=;j<Jih[i].size();j++) W(Jih[i][j]);
Bo=;
Used[i]++;
}
else
{
W(Jih[i][Jih[i].size()-]);
for(j=;j<Jih[i].size()-;j++) W(Jih[i][j]);
W(Jih[i][]);
Bo=;
}
}
}
puts("");
}
return ;
}
/*
input
4
1 3 3 1
output
YES
1 4 2 3
4 1 2 3
4 1 3 2
*/
codeforces471B的更多相关文章
随机推荐
- Java实现几种常见排序方法
日常操作中常见的排序方法有:冒泡排序.快速排序.选择排序.插入排序.希尔排序,甚至还有基数排序.鸡尾酒排序.桶排序.鸽巢排序.归并排序等. 以下常见算法的定义 1. 插入排序:插入排序基本操作就是将一 ...
- [01] Why Spring
1.何为框架 简单来说,框架就是制定了一套规范或者规则(思想),让程序员在该规范或规则下进行工作.如上图修楼房,在有框架的情况下,修建工作才高效且有条不紊.楼层钢架规定了大楼的结构,工人按架构添砖放瓦 ...
- 从0移植uboot (一) _配置分析
来源:Linux社区 作者:xiaojiang1025 :http://www.linuxidc.com/Linux/2017-02/141018.htm 和绝大多数源码编译安装一样,uboot的 ...
- C#去除字符串中的反斜杠
如下,可以使用C#的Replace()方法来替换,但有一点需要注意的是backslash(反斜杠)是特殊字符. string s = "[\"aaaaaaaaaaaaaaaaaaa ...
- (转)linux sudo 重定向,实现只有系统管理员才有权限操作的文件中写入信息
众所周知,使用 echo 并配合命令重定向是实现向文件中写入信息的快捷方式. 本文介绍如何将 echo 命令与 sudo 命令配合使用,实现向那些只有系统管理员才有权限操作的文件中写入信息. 比如 ...
- ASP.NET Core 登录失败。该登录名来自不受信任的域,不能与集成身份验证一起使用。
原文:ASP.NET Core 登录失败.该登录名来自不受信任的域,不能与集成身份验证一起使用. 当进行数据迁移的时候提示 修改appsettings配置连接串的Trusted_Connection ...
- Spring Cloud 入门教程(九): 路由网关zuul
在微服务架构中,需要几个关键的组件,服务注册与发现.服务消费.负载均衡.断路器.智能路由.配置管理等,由这几个组件可以组建一个简单的微服务架构.客户端的请求首先经过负载均衡(zuul.Ngnix),再 ...
- 利用matplotlib的plot函数实现图像绘制
模式识别的一个实验,要求画出贝叶斯决策的图.这里我是利用python中的matplotlib库实现的图线的拟合.主要对于matplotlib的使用可以参照博客:webary 如果要绘制三维图像可以参考 ...
- FFMPEG指令
FFmpeg是一个用于音视频处理的自由软件,被广泛用于音视频开发.FFmpeg功能强大,本文主要介绍如何使用FFmpeg命令行工具进行简单的视频处理. 安装FFmpeg可以在官网下载各平台软件包或者静 ...
- zabbix问题记录
zabbix部署好,在使用一段时间后,出现了不少报错,在此简单做一记录.1)Zabbix监控界面报错Lack of free swap space on Zabbix server”解决公司线上部署的 ...