2021-8-16 Mocha and Hiking

Posted 洛水天iriya

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2021-8-16 Mocha and Hiking相关的知识,希望对你有一定的参考价值。

难度 

题目 Codeforces:

Mocha and Hiking

The city where Mocha lives in is called Zhijiang. There are n+1n+1 villages and 2n12n−1 directed roads in this city.

There are two kinds of roads:

  • n1n−1 roads are from village ii to village i+1i+1, for all 1in11≤i≤n−1.
  • nn roads can be described by a sequence a1,,ana1,…,an. If ai=0ai=0, the ii-th of these roads goes from village ii to village n+1n+1, otherwise it goes from village n+1n+1 to village ii, for all 1in1≤i≤n.

Mocha plans to go hiking with Taki this weekend. To avoid the trip being boring, they plan to go through every village exactly once. They can start and finish at any villages. Can you help them to draw up a plan?

Input

Each test contains multiple test cases.

The first line contains a single integer tt (1t201≤t≤20) — the number of test cases. Each test case consists of two lines.

The first line of each test case contains a single integer nn (1n1041≤n≤104) — indicates that the number of villages is n+1n+1.

The second line of each test case contains nn integers a1,a2,,ana1,a2,…,an (0ai10≤ai≤1). If ai=0ai=0, it means that there is a road from village ii to village n+1n+1. If ai=1ai=1, it means that there is a road from village n+1n+1 to village ii.

It is guaranteed that the sum of nn over all test cases does not exceed 104104.

Output

For each test case, print a line with n+1n+1 integers, where the ii-th number is the ii-th village they will go through. If the answer doesn\'t exist, print 1−1.

If there are multiple correct answers, you can print any one of them.

 

题目解析

我吐了这道题,一直wa就是因为我想的太多,各种计算条件,反正是真的够惨的,本来上大分的,这题卡了老久了,不想解析了,看代码吧

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
int x[10005];
int main()
{//1是从临时点出来
    int t; cin >> t;
    while (t--)
    {
        ll n; cin >> n;

        for (int i = 0; i < n; i++)cin >> x[i];
        if (x[n - 1] == 0)
        {
            for (int i = 1; i <= n; i++)cout << i << " ";
            cout << n + 1 << "\\n";
        }
        else if (x[0] == 1)
        {
            cout << n + 1;
            for (int i = 1; i <= n; i++)cout << " " << i;
            cout << "\\n";
        }
        else
        {
            bool tf = 1;
            for (int i = 1; i <= n; i++)
            {
                if (tf && i < n && x[i - 1] == 0 && x[i] == 1)
                {
                    cout << i << " " << n + 1 << " ";
                    tf = 0;
                }
                else if (i != n) cout << i << " ";
                else if (i == n) cout << i;
            }
            cout << "\\n";
        }
    }
    return 0;
}

 

以上是关于2021-8-16 Mocha and Hiking的主要内容,如果未能解决你的问题,请参考以下文章

CF #738(div2)A. Mocha and Math(贪心)

CF #738(div2)C. Mocha and Hiking(构造)

[Node.js] Test Node RESTful API with Mocha and Chai

CF #738(div2)D2. Mocha and Diana (Hard Version)(贪心,并查集)

CF #738(div2)D1. Mocha and Diana (Easy Version)(暴力,并查集)

[CF1559D2]Mocha and Diana(hard version)