CF #330 C

來源:互聯網
上載者:User

標籤:

改了題目之後,就是沒有奇數的測試了。。。

其實可以很輕易地發現,要距離近的一方只會刪除兩端的,而要求遠的一方會刪除中間的。

那麼,很明顯的,剩下的兩點會相差x/2個節點,於是,只要計算i和i+x/2的節點的距離即可。取最小的值。

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#define LL long longusing namespace std;///vector<int>f;LL f[200050];int main(){/// int n;LL t;    int n; LL t;    while(scanf("%d",&n)!=EOF){    /// f.clear();        for(int i=0;i<n;i++)            cin>>f[i];///f.push_back(t);    /*  for(int i=0;i<n;i++)            cin>>t,f.push_back(t);*/        sort(f,f+n);    //  sort(f.begin(),f.end());    /// bool flag=n%2?true:false;    /*  while(n>2){            if(f[n-1]-f[1]<=f[n-2]-f[0]) f.erase(f.begin()+0);            else f.erase(f.begin()+n-1);            n--;            f.erase(f.begin()+n/2);            n--;        }*/    /// cout<<f[1]-f[0]<<endl;        LL ans=1e9;        for(int i=0;i+n/2<n;i++){            ans=min(ans,f[i+n/2]-f[i]);        }        cout<<ans<<endl;    }    return 0;}

  

CF #330 C

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.