A. Filling Diamonds
Topic: Ask $ n $ diamonds to make the diamond shown
Idea: It is obvious that there are $ n $ standing diamonds in each graph, and choosing one of them will become lying, so the answer is $ n $
#include<iostream> #include<cstdio> using namespace std; int main(){ int t,x; cin>>t; while(t--){ cin>>x; cout<<x<<endl; } return 0; }
B - Sorted Adjacent Differences
Topic: Given an array, after rearranging, the absolute value of adjacent elements does not decrease
Idea: After sorting, place the array upside down
#include<iostream> #include<algorithm> #include<vector> #include<map> using namespace std; typedef long long ll; const int maxn=1e5+10; ll a[maxn],ans[maxn]; int main () { int t,n; scanf("%d",&t); while(t--){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+1+n); int l=1,r=n; for(int i=n;i>=1;i--){ if((n-i)%2==0){ ans [i] = a [l ++ ]; } if((n-i)%2==1){ ans[i]=a[r--]; } } for(int i=1;i<=n;i++){ if(i!=1) printf(" "); printf("%d",ans[i]); } cout<<endl; } return 0; }
C - Powered Addition
Topic: For an array, you can add $ 2 ^ {x-1} $ to some elements in the first $ x $ second, ask how many seconds the array can become a non-decreasing sequence
Idea: Find the group of elements with the largest difference between the front and the back of the array, and then determine the need to add a few seconds
#include<iostream> #include<algorithm> using namespace std; const int maxn=1e5+10; int a[maxn]; int main() { int t,n; scanf("%d",&t); while(t--){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); int mi=a[n],flag=0,ret=0; for(int i=n-1;i>=1;i--){ if(a[i]>mi) flag=1,ret=max(ret,a[i]-mi); else mi=min(a[i],mi); } if(!flag) cout<<0<<endl; else{ int x=1,cnt=0; while(ret>0){ right - = x; x*=2; cnt++; } cout<<cnt<<endl; } } return 0; }