codeforce 702C Cellular Network 二分答案

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 0x7fffffff
21 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 }
时间: 2024-11-05 01:11:48

codeforce 702C Cellular Network 二分答案的相关文章

CodeForces - 702C Cellular Network

You are given n points on the straight line - the positions (x-coordinates) of the cities and m points on the same line - the positions (x-coordinates) of the cellular towers. All towers work in the same way - they provide cellular network for all ci

codeforces 702C C. Cellular Network(水题)

题目链接: C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given n points on the straight line — the positions (x-coordinates) of the cities and m points on the same

poj 2349 Arctic Network MST/二分答案

poj 2349 Arctic Network 题目传送 Sol: 方法一: 贪心的想,发现n个点只需要n-1条边即可,求MST即可,再把MST中最大的m-1条边去掉,第m大就是答案. code: #include<string> #include<cmath> #include<cstdio> #include<cstring> #include<algorithm> #define IL inline #define RG register

Codeforce 371C Hamburgers (二分答案)

题目链接 Hamburgers 二分答案,贪心判断即可. 1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 #define REP(i,n) for(int i(0); i < (n); ++i) 6 #define LL long long 7 8 char str[1010]; 9 LL len; 10 LL b, c, s, nb, nc, ns, pb, pc, ps; 11 LL money; 12 13 bool

Educational Codeforces Round 15_C. Cellular Network

C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given n points on the straight line — the positions (x-coordinates) of the cities and m points on the same line

cf702C Cellular Network

C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given n points on the straight line — the positions (x-coordinates) of the cities and m points on the same line

CodeForce-702C Cellular Network(查找)

Cellular Network CodeForces - 702C 给定 n (城市数量) 和 m (灯塔数量): 给定 a1~an 城市坐标: 给定 b1~bm 灯塔坐标: 求出灯塔照亮的最小半径 r ,使得所有城市都能被照亮. Input 3 2-2 2 4-3 0 Output 4 Input 5 31 5 10 14 174 11 15 Output 3 题解: 首先对于每个城市 a[ i ],找到离它最近的左右两个灯塔  b [ x ] , b [ x-1 ](只有最左或最右灯塔时

bzoj 3597 [Scoi2014] 方伯伯运椰子 - 费用流 - 二分答案

题目传送门 传送门 题目大意 给定一个费用流,每条边有一个初始流量$c_i$和单位流量费用$d_i$,增加一条边的1单位的流量需要花费$b_i$的代价而减少一条边的1单位的流量需要花费$a_i$的代价.要求最小化总费用减少量和调整次数的比值(至少调整一次). 根据基本套路,二分答案,移项,可以得到每条边的贡献. 设第$i$条边的流量变化量为$m_i$,每次变化花费的平均费用为$w_i$.那么有 $\sum c_id_i - \sum (c_i + m_i)d_i + |m_i|(w_i + mi

Codeforces 772A Voltage Keepsake - 二分答案

You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power store