Codeforces Round#633(Div。2)

A.ダイヤモンドの充填

トピック: $ n $個のダイヤモンドを要求して、ダイヤモンドを表示させます

アイデア:各グラフに$ n $の立っているダイヤモンドがあることは明らかであり、それらの1つを選択すると嘘になるので、答えは$ n $です。

#include <iostream> 
#include <cstdio>
  using  namespace std;
int main(){
     int t、x; 
    cin >> t;
    while(t-- ){ 
        cin >> x; 
        cout << x << endl; 
    } 
    0を返し ます
}
コードを表示

B-並べ替えられた隣接する差異

トピック:配列を指定した場合、再配置後、隣接する要素の絶対値は減少しません

アイデア:並べ替え、アレイを上下逆にします

#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);
         forint i = 1; i <= n; i ++)scanf(" %d "、&​​a [i]); 
         sort(a + 1、a + 1 + n);
         int l = 1、r = n;
         forint i = n; i> = 1 ; i -- ){
              if((ni)%2 == 0 ){ 
                 ans [i] = a [l ++ ]; 
             } 
            if((ni)%2 == 1 ){ 
                ans [i] = a [r-- ]; 
            } 
         }
        forint i = 1 ; i <= n; i ++ ){
             if(i!= 1)printf("  " ); 
            printf(" %d " 、ans [i]); 
        } 
        cout << endl; 
     } 
     0を返し ます
 }
コードを表示

C-パワードアディション

トピック:配列の場合、最初の$ x $秒のいくつかの要素に$ 2 ^ {x-1} $を追加し、配列が減少しないシーケンスになることができる秒数を尋ねます

アイデア:アレイの前面と背面の違いが最も大きい要素のグループを見つけ、数秒追加する必要性を判断します

#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);
         forint i = 1 ; i <= n; i ++)scanf(" %d "、&​​a [i]);
         int mi = a [n]、flag =0、ret = 0 ;
         INT I = N- 1、I> = 1 ; i-- ){
              場合([i]が> MI)フラグ= 1、RET = MAX(RET、[I] - MI)。
             それ以外の場合、 mi = min(a [i]、mi); 
         } 
        if(!flag)cout << 0 << endl;
        else {
             int x = 1、cnt = 0 ;
            while(ret> 0 ){ 
                ret- = x; 
                x * =2 ; 
                cnt ++ ; 
            } 
            cout << cnt << endl; 
        } 
     } 
    return  0 ; 
 }
コードを表示

 

おすすめ

転載: www.cnblogs.com/overrate-wsj/p/12690953.html