/ Randle /

记录详情

Accepted

/in/foo.cc: In function 'bool WORK(int, int)':
/in/foo.cc:13:6: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
      if (r-l+1<C) return false; o=0;
      ^~
/in/foo.cc:13:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
      if (r-l+1<C) return false; o=0;
                                 ^
# 状态 耗时 内存占用
#1 Accepted 2ms 324.0 KiB
#2 Accepted 1ms 308.0 KiB
#3 Accepted 1ms 312.0 KiB
#4 Accepted 1ms 316.0 KiB
#5 Accepted 1ms 312.0 KiB
#6 Accepted 5ms 316.0 KiB
#7 Accepted 4ms 320.0 KiB
#8 Accepted 7ms 308.0 KiB
#9 Accepted 27ms 312.0 KiB
#10 Accepted 40ms 316.0 KiB

代码

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
struct node {int x,y;} a[1005];
int C,n,L,R,mid,b[1005],o,i;
int cmp(node i,node j) {return i.x<j.x;}
int CMP(int i,int j) {return i<j;}
bool WORK(int l,int r)
{
     if (r-l+1<C) return false; o=0;
     for (int i=l; i<=r; i++) b[++o]=a[i].y;
     sort(b+1,b+o+1,CMP);
     for (int i=C; i<=o; i++)
       if (b[i]-b[i-C+1]<=mid) return true;
      return false;
}
bool OK(int x)
{
    int l=1;
    for (int i=1; i<=n; i++)
    {
        if (a[i].x-a[l].x>x)
        {
                             if (WORK(l,i-1)) return true;
                             while (a[i].x-a[l].x>x) l++;
        }
    }
    if (WORK(l,n)) return true;
    return false;
}
int main()
{
    scanf("%d%d",&C,&n);
    for (i=1; i<=n; i++)
        scanf("%d%d",&a[i].x,&a[i].y);
    sort(a+1,a+n+1,cmp);
    L=0; R=10000; mid=(L+R)/2;
    while (L<=R)
    {
          if (OK(mid)) {R=mid-1; mid=(L+R)/2;} else
          {
                       L=mid+1;
                       mid=(L+R)/2;
          }
    }
    cout<<L+1;
    return 0;
}

信息

递交者
类型
递交
题目
正方形 T2
题目数据
下载
语言
C++
递交时间
2017-10-04 14:08:30
评测时间
2017-10-04 14:08:30
评测机
分数
100
总耗时
93ms
峰值内存
324.0 KiB