CodeForces - 831D Office Keys
生活随笔
收集整理的這篇文章主要介紹了
CodeForces - 831D Office Keys
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意解析
二分貪心
#include <iostream> #include <algorithm> #include <cstdio> #define ll long long #define maxn 100010 using namespace std; int n,k,p; int a[maxn],b[maxn]; int main() {cin>>n>>k>>p;for(int i=0;i<n;++i){scanf("%d",&a[i]);}for(int i=0;i<k;++i){scanf("%d",&b[i]);}sort(a,a+n);sort(b,b+k);ll low=0,high=1e18,tag,mid,ans,an;while(low<high){mid=low+(high-low)/2;tag=0,ans=0;for(int i=0;i<n;++i){for(int j=tag;j<k;++j){if(abs(a[i]-b[j])+abs(b[j]-p)<=mid){ans++;tag=j+1;break;}}}if(ans==n){an=mid;high=mid;}elselow=mid;}cout<<an<<endl;}總結
以上是生活随笔為你收集整理的CodeForces - 831D Office Keys的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: codeforces831c 思维
- 下一篇: hdu 1258 确定比赛名次