Codeforces Round#635(Div.2)

     タイトル:a、b、c、dを与えます。三角形を形成する3つの間隔a〜b〜c〜dのそれぞれから数を求めます。

     分析:三角形の性質により、出力a、c、cは実行可能なソリューションです。小さいものから大きいものに出力することを忘れないでください。

#include <iostream> 
#include <vector> 
#include <cstring>
 using  namespace std; 
typedef long  long ll;
const  int maxn = 1e5 + 10 ;
const  int inf = 0x3f3f3f3f ;
int main()
{ 
    int t; 
    cin >> t;
    while(t-- 
    { 
        ll a、b、c、d; 
        cin >> a >> b >> c >> d; 
        cout << a << "  " << c << << c << endl; 
    } 
}

     タイトルの意味:x、n、m。ドラゴンにはx滴の血があり、操作があります:血液量/ 2 + 10-> n回まで。血液量-10->最大でm回。ドラゴンを殺せるかどうか尋ねる

     分析:操作1の場合、血液量が<20の場合、/ 2 + 10の値を増やす必要があることがわかります。それでは、最初に操作を行い、20未満になると中断します。次に、この残りの血液量-10 * mを取得して、0未満かどうかを確認します。

#include <iostream> 
#include <vector> 
#include <cstring>
 using  namespace std; 
typedef long  long ll;
const  int maxn = 1e5 + 10 ;
const  int inf = 0x3f3f3f3f ;
int main()
{ 
    int t; 
    cin >> t;
    while(t-- 
    { 
        int x、n、m; 
        cin >> x >> n >> m;
        int cnt = 0 ;
        int k =バツ;
        forint i = 1 ; i <= n; i ++ 
        {     
            x = x / 2 + 10 ;
            if(x < 20 break ; 
            k = x;                                
        } 
    //     cout << k << endl; 
        k = km * 10 ;
        if(k> 0 
            cout << " NO " << endl;
        他の
            coutの <<はい << endl; 
    } 
}

     トピック:1〜nポイントの完全なツリー、ルートは1つだけです。各ポイントは都市です。今度は、k都市を工業都市に、他の都市を観光都市に変える必要があります。これらの各工業都市は、ポイント1に人を送り、途中で最大の観光都市にし、この値を出力します。

     分析:私はゲーム中のエントリー問題に苦労しただけで、私の考えは広がりませんでした。このツリーにはリングがないため、ここでは最短パスを考慮する必要はありません。kポイントを取ると、最初の考えは最も深いポイントから開始することです。深さは、現在のポイントがポイント1まで通過するポイントの数です(サンプル1、深さ[5] = 2など)。深度を大から小にソートします。フェッチプロセス中に問題が発生します。ポイントFを取得したと仮定すると、その子ノードも取得する必要があります。都市の数が変わりました。つまり、ポイントを取ると、その子供がポイント1に到達する観光都市の数は-1になります。したがって、そのサイズの子ノードの数を記録する必要があります。次に、各ポイントの寄与は、deep [i]-(size [i] -1)です。なぜ-1?サイズ[i]にはi自体が含まれているため、計算時に削除する必要があります。

      写真を保存するためにチェーンフォワードスターが使用されています。それについては、この兄の説明をお勧めしますhttps : //blog.csdn.net/sugarbliss/article/details/86495945

      ディープ[]とサイズ[]をシークするプロセスに関しては、dfsのバックトラックが使用されます。つまり、ポイントのすべての子ノードを見つけ、その子ノードからポイント1に戻ります。 []蓄積します。Xiaobaiの便宜のために、例1のdfsプロセスを次に示します。

#include <stdio.h> 
#include <iostream> 
#include <algorithm> 
#include < string .h> 
#include <vector> 
#include <cmath> 
#include < string > 
#include <map> 
#include <queue>
 using  名前空間std; 
typedef long  long ll;
const  int maxn = 2e5 + 10 ;
int head [maxn]、deep [maxn]、siz [maxn];
int cnt = 0 ;
構造ノード
{ 
    intto、nxt; 
} edge [ 4 * maxn];
void add(int u、int v)
{ 
    edge [cnt] .to = v; 
    edge [cnt] .nxt = head [u]; 
    head [u] = cnt ++ ; 
} 
void dfs(int u、int v、int d)
{ 
    deep [u] = d; 
    siz [u] = 1 ;
    forint i = head [u]; i!=- 1 ; i = edge [i] .nxt)
    { 
        int to =edge [i] .to;
        if(to == v)
             続行; 
        dfs(to、u、d + 1 ); 
        siz [u] + = siz [to]; 
    } 
} 
int main()
{ 
    int n、k; 
    memsetの(頭、 - 1はsizeof (ヘッド))。
    cin >> n >> k;
    int a、b;
    forint i = 1 ; i <n; i ++ 
    { 
        cin >> a >> b; 
        add(a、b); 
        add(b、a);
    } 
    dfs(1、 - 10 );
    forint i = 1 ; i <= n; i ++ 
    { 
        deep [i] -=(siz [i] -1 ); 
    } 
    sort(deep + 1、deep + 1 + n); 
    ll sum = 0 ;
    int j = n;
    forint i = 1 ; i <= k; i ++ 
        { 
            sum + = deep [j]; 
            J - 
    coutの ;
        } << sum << endl; 
}

 

 

 

 

おすすめ

転載: www.cnblogs.com/liyexin/p/12716741.html