zoukankan      html  css  js  c++  java
  • Codeforces Round #200 (Div. 2)E

    Read Time

    题意:有一个数组,很多指针指在这个数组上,每次每个指针可以向左或向右移动一个位置。给出一些需要访问的位置,问访问用的最少时间。

    一个指针只可能转一次方向。二分答案。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #define MAX(a,b) a>b?a:b
     5 using namespace std;
     6 long long ans,hh,tt,mid,a[110000],b[110000];
     7 int i,n,m;
     8 bool can(long long x)
     9 {
    10     int i,now,j=1;
    11     long long xx,yy;
    12     
    13     for (i=1;i<=n;i++)
    14     {
    15         if (b[j]<a[i])
    16             xx=a[i]-b[j];
    17         else
    18             xx=0;
    19         if (xx>x) return 0; 
    20         yy=MAX((x-xx)/2,x-xx*2);
    21         while (b[j]<=a[i]+yy&&j<=m)
    22             j++;
    23         if (j>m) return 1;
    24     }
    25     if (j<=m) return 0;
    26     else
    27         return 1;
    28 }
    29 int main()
    30 {
    31     scanf("%d%d",&n,&m);
    32     for (i=1;i<=n;i++)
    33         scanf("%I64d",&a[i]);
    34     for (i=1;i<=m;i++)
    35         scanf("%I64d",&b[i]);
    36     sort(a+1,a+1+n);
    37     sort(b+1,b+1+m);
    38     hh=0;tt=15000000000;
    39     while (hh<=tt)
    40     {
    41         mid=(hh+tt)>>1;
    42         if (can(mid))
    43         {
    44             ans=mid;
    45             tt=mid-1;
    46         }
    47         else
    48             hh=mid+1;
    49     }
    50     printf("%I64d
    ",ans);    
    51 }
    View Code
    #WhenWhoProblemLangVerdictTimeMemory
    20227903 2016-08-29 13:56:53 lbz007 E - Read Time GNU C++ Accepted 108 ms 1500 KB

    ------------------------------------------------------------------------- 花有重开日,人无再少年
  • 相关阅读:
    2017/4/14 afternoon
    2017/4/14 morning补
    2017/4/13 afternoon
    2017/4/13 morning
    2017/4/12 afternoon
    2017/4/12 morning
    4.17上午
    4.14上午
    4.13下午
    4.13上午
  • 原文地址:https://www.cnblogs.com/lbz007oi/p/5819357.html
Copyright © 2011-2022 走看看