zoukankan      html  css  js  c++  java
  • 数据读取

    源代码:
    
    #include<cstdio>
    #include<iostream>
    #define LL long long
    using namespace std;
    LL m,n,i[100001],f[100001]; //为什么数据类型都这么坑爹!
    bool Check(LL Mid) //模拟+贪心=Check(),后面的目标显然都已扫描过了。
    {
        for (LL a=1,b=1;a<=n;a++)
        {
            if (i[a]-f[b]>Mid) //再往下肯定还超,因为递增,所以非法。
              return false;
            LL End; //最终指针能够到达的点。
            if (f[b]<i[a]) //目标在指针后面。
            {
                LL T=Mid-(i[a]-f[b]);
                End=max(f[b]+T,i[a]+T/2); //先左再右与先右再左。
            }
            else
              End=i[a]+Mid; //目标在指针前面,只能向前。
            while (f[b]<=End&&b<=m) //更新目标。
              b++;
            if (b>m) //目标都已处理完毕。
              return true;
        }
        return false; //非True即False。
    }
    int main()
    {
        cin>>n>>m; //Windows下用scanf()应用%I64d。
        for (LL a=1;a<=n;a++)
          cin>>i[a]; //指针。
        for (LL a=1;a<=m;a++)
          cin>>f[a]; //目标。
        LL Left=0,Right=(LL)1e10,Ans=0;
        while (Left<=Right) //二分答案。
        {
            LL Mid=(Left+Right)/2;
            if (Check(Mid))
            {
                Ans=Mid;
                Right=Mid-1;
            }
            else
              Left=Mid+1;
        }
        cout<<Ans;
        return 0;
    }
  • 相关阅读:
    使用Power Shell 拉取项目源代码
    C# 读取excel数据到datatable
    C# 导出datatable数据到excel
    redis过一段时间连接不上
    windows10 docker volume
    通过端口查询到应用
    centos清理磁盘
    maven镜像加速
    IDEA常用插件
    java开发常用软件
  • 原文地址:https://www.cnblogs.com/Ackermann/p/5992951.html
Copyright © 2011-2022 走看看