A. Suborrays
原题链接:https://codeforces.com/contest/1391/problem/A
A permutation of length is an array consisting of distinct integers from to in arbitrary order. For example, is a permutation, but is not a permutation 2 appears twice in the array and is also not a permutation but there is in the array .
For a positive integer , we call a permutation p of length n good if the following condition holds for every pair and —
- , where denotes the bitwise operation.
In other words, a permutation is good if for every subarray of , the of all elements in it is not less than the number of elements in that subarray.
Given a positive integer , output any good permutation of length . We can show that for the given constraints such a permutation always exists.
Input
Each test contains multiple test cases. The first line contains the number of test cases
. Description of the test cases follows.
The first and only line of every test case contains a single integer .
Output
For every test, output any good permutation of length n on a separate line.
Example
input
3
1
3
7
output
1
3 1 2
4 3 5 2 7 1 6
Note
For n = 3,
is a good permutation. Some of the subarrays are listed below.
-
Similarly, you can verify that is also good.
题意:输入一个长度n,用
~
的数字进行随机排列。定义对于一个正整数n,如果对于每一对
和
都满足,对于p的每个子数组,其中所有元素的OR不小于该子数列中元素的个数。我们称长度为
的排列
是好的。
题解:两个数进行位运算了,且范围是1~n,那么进行位运算后的结果不会小于元素的个数。简而言之就是:无论怎么输出这个置换序列都是正确的。(我是逆序输出的。)
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
for (int i = n; i >= 1; i--)
printf("%d ",i);
cout << endl;
}
return 0;
}
其实这次的div2做的有点像div3的难度。