A. Suborrays
http://codeforces.com/contest/1391/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 ( 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 of length good if the following condition holds for every pair and ( ) —
, where denotes the bitwise OR 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 on a separate line.
Example
input
3
1
3
7
output
1
3 1 2
4 3 5 2 7 1 6
Note
For , is a good permutation. Some of the subarrays are listed below.
Similarly, you can verify that is also good.
翻译:
一个排列permutation长度为 是一个数组,组成consisting 是n个不同的整数从 到 任意arbitrary 顺序 order。例如, , 是一个排列,但是 不是一个排列(2出现了两次在数组里) 并且 也不是排列(n = 3 但是这里有 4 在数组里)。
对于正整数 n,我们叫排列 P 长度为 n 是好,如果他以下following 情况condition 保持,对于每一对 and ( ) — ,,其中OR代表denotes 按位bitwise OR 运算符 operation 运算
换句话说In other words,P排列是一个好的 如果对于每一个子数组subarray 从P中,所有元素的OR不小于元素的数量在子数组中。
给一个正整数 N,输出任意好的排列 长度为 n。我们证明show 对于给定的约束constraints ,这样的一个排列总是存在的。
题意:
给你一个从 1 到 n 的数组,求一个排列,满足上面的式子。
题解:
有个 OR 的规律:
所以任意两个
,一定大于两个数相加。
那么,将数组从 1 到 n 输出,就算每次增加最小的加一,最后也是满足上面的规则。
代码:
#include <bits/stdc++.h>
using namespace std;int main(void)
{int T;cin>>T;while(T--){int n;cin>>n;for(int i=1; i<=n; i++){cout<<i<<" ";}cout<<endl;}return 0;
}