codeforce 702C Cellular Network 二分答案

來源:互聯網
上載者:User

標籤:

http://codeforces.com/contest/702

題意:n個村莊,m個機站,問機站最短半徑覆蓋完所有村莊

思路:直接二分答案

二分太弱,調了半天。。。。。

 1 // #pragma comment(linker, "/STACK:102c000000,102c000000") 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 #include <sstream> 6 #include <string> 7 #include <algorithm> 8 #include <list> 9 #include <map>10 #include <vector>11 #include <queue>12 #include <stack>13 #include <cmath>14 #include <cstdlib>15 // #include <conio.h>16 using namespace std;17 #define pi acos(-1.0)18 const int N = 1e5+10;19 const int MOD = 1e9+7;20 #define inf 0x7fffffff21 typedef long long  LL;22 23 void frein(){freopen("in.txt","r",stdin);}24 void freout(){freopen("out.txt","w",stdout);}25 inline int read(){int x=0,f=1;char ch=getchar();while(ch>‘9‘||ch<‘0‘) {if(ch==‘-‘) f=-1;ch=getchar();}while(ch>=‘0‘&&ch<=‘9‘) { x=x*10+ch-‘0‘;ch=getchar();}return x*f;}26 27 int a[N];28 int b[N];29 30 int main(){31     // frein();32     // freout();33     int n,m;34     scanf("%d%d",&n,&m);35     for(int i=1;i<=n;i++) scanf("%d",&a[i]);36     for(int i=1;i<=m;i++) scanf("%d",&b[i]);37     LL l=0,r=2e9;38     while(l<r){39        LL mid=(l+r)>>1;40        int j=1;41        bool flag=false;42        for(int i=1;i<=n;i++){43           if(j>m){44             flag=true;45             break;46           }  47           if(fabs(b[j]-a[i])<=mid){48             continue;49           }50           else{51             j++;52             i--;53           }54        }    55        if(flag){56           l=mid+1;57        }58        else{59           r=mid;60        }61     }62     printf("%I64d\n",l);63     return 0;64 }

 

codeforce 702C Cellular Network 二分答案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.