--- title: "无线网络" created: 2025-11-28 tags: - 算法 --- # 无线网络 ## 题目 [无线网络](https://www.acwing.com/problem/content/description/3976/) ![[image-90a786c0.png]] ## 思路分析 找每头牛最近的两个基站 如果发现有一头牛距离两个基站的距离都大于mid(覆盖不到) 就说明mid取小了 ## 代码实现 ```cpp #include using namespace std; #define endl '\n' typedef long long LL; const int N=1e5+10; int a[N],b[N]; int n,m; bool check(int mid){ for(int i=0,j=0;imid){ if(j+1>=m || abs(b[j+1]-a[i])>mid) return false; } } return true; } int main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin>>n>>m; for(int i=0;i>a[i]; for(int i=0;i>b[i]; int l=0,r=2e9; while(l>1; if(check(mid)) r=mid; else l=mid+1; } cout<