B. Special Permutation(思维)

B. Special Permutation
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

A permutation of length nn is an array p=[p1,p2,,pn]p=[p1,p2,…,pn] which contains every integer from 11 to nn (inclusive) exactly once. For example, p=[4,2,6,5,3,1]p=[4,2,6,5,3,1] is a permutation of length 66.

You are given three integers nn, aa and bb, where nn is an even number. Print any permutation of length nn that the minimum among all its elements of the left half equals aa and the maximum among all its elements of the right half equals bb. Print -1 if no such permutation exists.

Input

The first line of the input contains one integer tt (1t10001≤t≤1000), the number of test cases in the test. The following tt lines contain test case descriptions.

Each test case description contains three integers nn, aa, bb (2n1002≤n≤100; 1a,bn1≤a,b≤n; aba≠b), where nn is an even number (i.e. nmod2=0nmod2=0).

Output

For each test case, print a single line containing any suitable permutation. Print -1 no such permutation exists. If there are multiple answers, print any of them.

Example
input
7
6 2 5
6 1 3
6 4 3
4 2 4
10 5 3
2 1 2
2 2 1
output
4 2 6 5 3 1
-1
6 4 5 1 3 2 
3 2 4 1 
-1
1 2 
2 1 

题意:输入三个数n,a,b,n保证为偶数,输出使得a是左半边的最小值,b是右半边的最大值。

感觉难度主要体现在判断错误上,直接附上代码

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 int t,n,a,b,cnta = 0,cntb = 0;
 5 bool vis[109];
 6 int main()
 7 {
 8     scanf("%d",&t);
 9     while(t--)
10     {
11         scanf("%d%d%d",&n,&a,&b);
12         memset(vis,0,sizeof(vis));
13         vis[a] = 1,vis[b] = 1,cnta = 0,cntb = 0;
14         for(int i = a;i <= n;i++) if(!vis[i]) cnta++;
15         for(int i = b;i > 0;i--) if(!vis[i]) cntb++;
16         if(cnta >= n/2-1 && cntb >= n/2-1)
17         {
18             for(int i = n,j = 0;j < n/2-1;i--)
19             {
20                 if(!vis[i])
21                 {
22                     printf("%d ",i);
23                     vis[i] = 1;
24                     j++;
25                 }
26             }
27             printf("%d ",a);
28             for(int i = 1,j = 0;j < n/2-1;i++)
29             {
30                 if(!vis[i])
31                 {
32                     printf("%d ",i);
33                     vis[i] = 1;
34                     j++;
35                 }
36             }
37             printf("%d",b);
38             printf("\n");
39         } 
40         else printf("-1\n");
41     }
42 }

 

 

 

posted @ 2021-11-24 20:40  wbw1537  阅读(172)  评论(0)    收藏  举报