CodeForces - 1339A&CodeForces - 1339B(물)
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.
On the left you can see the diamond shape you will use, and on the right you can see the area you want to fill. These are the figures of the area you want to fill for n=1,2,3,4.
You have to answer t independent test cases.
Input The first line contains a single integer t (1≤t≤104) — the number of test cases.
Each of the next t lines contains a single integer n (1≤n≤109).
Output For each test case, print the number of ways to fully cover belt-like area of 4n−2 triangles using diamond shape. It can be shown that under given constraints this number of ways doesn’t exceed 1018.
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
#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;
}
Sorted Adjacent Differences CodeForces - 1339B You have array of n numbers a1,a2,…,an.
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.
Input The first line contains a single integer t (1≤t≤104) — the number of 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).
Output For each test case, print the rearranged version of array a which satisfies given condition. If there are multiple valid rearrangements, print any of them.
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
#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;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.