Diamond shape consists of two triangles. You can move, rotate or flip the shape, but you cannot scale it.
2 coverings are different if some 2 triangles are covered by the same diamond shape in one of them and by different diamond shapes in the other one.
Please look at pictures below for better understanding.
You have to answer t independent test cases.
Each of the next t lines contains a single integer n (1≤n≤109).
Example
Input
2
2
1
Output
2
1
Note
In the first test case, there are the following 2 ways to fill the area:
In the second test case, there is a unique way to fill the area:
思路:直接输出n就好啦。
代码如下:
#include<bits/stdc++.h> #define ll long long using namespace std; int n; int main() {
int t; scanf("%d",&t); while(t--) {
cin>>n; cout<<n<<endl; } return 0; }
讯享网
Rearrange these numbers to satisfy |a1−a2|≤|a2−a3|≤…≤|an−1−an|, where |x| denotes absolute value of x. It’s always possible to find such rearrangement.
Note that all numbers in a are not necessarily different. In other words, some numbers of a may be same.
You have to answer independent t test cases.
The first line of each test case contains single integer n (3≤n≤105) — the length of array a. It is guaranteed that the sum of values of n over all test cases in the input does not exceed 105.
The second line of each test case contains n integers a1,a2,…,an (−109≤ai≤109).
Example
Input
2
6
5 -2 4 8 6 5
4
8 1 4 2
Output
5 5 4 6 8 -2
1 2 4 8
Note
In the first test case, after given rearrangement, |a1−a2|=0≤|a2−a3|=1≤|a3−a4|=2≤|a4−a5|=2≤|a5−a6|=10. There are other possible answers like “5 4 5 6 -2 8”.
In the second test case, after given rearrangement, |a1−a2|=1≤|a2−a3|=2≤|a3−a4|=4. There are other possible answers like “2 4 8 1”.
思路:排序之后,靠的越近的差值绝对值越小,反之则越大。因此排序之后,从中间往两边输出就可以了。
代码如下:
讯享网#include<bits/stdc++.h> #define ll long long using namespace std; const int maxx=1e5+100; int a[maxx]; int n; int main() {
int t; scanf("%d",&t); while(t--) {
scanf("%d",&n); for(int i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+1+n); if(n&1) cout<<a[n/2+1]<<" "; int l,r; if(n&1) l=n/2,r=n/2+2; else l=n/2,r=n/2+1; while(l>=1) {
cout<<a[l]<<" "<<a[r]<<" "; l--,r++; } cout<<endl; } return 0; }

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/68161.html