CodeForces 471B MUH and Important Things

    xiaoxiao2026-04-13  3

    题目:

    Description

    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 n 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 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 n 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.

    Sample Input

    Input 4 1 3 3 1 Output YES 1 4 2 3 4 1 2 3 4 1 3 2 Input 5 2 4 1 4 8 Output NO

    Hint

    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.

    题目就是要输出3种顺序,如果不足3种就是NO。

    比如输出的1 4 2 3表示的是第1个数、第4个数、第2个数、第3个数这样的顺序。

    要找3种不同的顺序,使得得到的都是单调不减的数列。

    对于本题,只需要找3种,可以分类讨论。

    1,如果有1个数出现了3次,那么这3个数就有了6种顺序。

    2,如果每个数都只出现1次或者2次,1次的当然没什么用,要看有多少个数出现了2次。

    如果只有1个的话,那么答案就是NO,否则,2个数各出现了2次就有了4种顺序。

    代码:

    #include<iostream> #include<algorithm> using namespace std; struct node { int number; int key; }; node nod[2001]; int num[2001]; bool cmp(node a,node b) { return a.number < b.number; } int main() { int n, a, f1 = 0, f2 = 0; cin >> n; for (int i = 1; i <= n; i++) { cin >> a; nod[i].number = a; nod[i].key = i; num[a]++; if (num[a] > 1) { if (f1 == 0)f1 = a; else f2 = a; } } sort(nod + 1, nod + 1 + n, cmp); if (f1) { if (num[f1] >2) { cout << "YES" << endl; int k; for (int i = 1; i <= n; i++) { if (nod[i].number == f1)k = i; cout << nod[i].key << " "; } cout << endl; for (int i = 1; i <= n; i++) { if (i == k - 2) { cout << nod[k - 1].key << " " << nod[k - 2].key << " "; i += 2; } cout << nod[i].key << " "; } cout << endl; for (int i = 1; i <= n; i++) { if (i == k - 1) { cout << nod[k].key << " " << nod[k - 1].key << " "; i++; continue; } cout << nod[i].key << " "; } cout << endl; } else if (f2) { cout << "YES" << endl; for (int i = 1; i <= n; i++)cout << nod[i].key << " "; cout << endl; for (int i = 1; i <= n; i++) { if (nod[i].number == f1) { cout << nod[i + 1].key << " " << nod[i].key << " "; i++; continue; } cout << nod[i].key << " "; } cout << endl; for (int i = 1; i <= n; i++) { if (nod[i].number == f2) { cout << nod[i + 1].key << " " << nod[i].key << " "; i++; continue; } cout << nod[i].key << " "; } cout << endl; } else cout << "NO" << endl; } else cout << "NO" << endl; return 0; }

    转载请注明原文地址: https://ju.6miu.com/read-1308786.html
    最新回复(0)