【题目链接】

http://poj.org/problem?id=3179

【算法】

首先,我们发现答案是具有单调性的,也就是说,如果边长为C的正方形可以,那么比边长C大的正方形也可以,因此,可以二分答案

那么,我们怎么检验呢?

每个点的坐标最大时达到10000,因此,直接二维前缀和显然是会超时的

考虑将坐标离散化,然后求二维前缀和,由于N<=500,所以离散化后最多也只有1000个点

检验时,我们枚举正方形的左上角,用二分求出它的右下角,然后,判断正方形内是否有大于C的草量

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 510 int C,N,i,j,l,r,mid,ans,tx,ty,len;
int tmp[MAXN<<],s[MAXN<<][MAXN<<],x[MAXN],y[MAXN]; inline int getsum(int xa,int ya,int xb,int yb)
{
return s[xb][yb] - s[xa-][yb] - s[xb][ya-] + s[xa-][ya-];
}
inline bool check(int x)
{
int i,j,tx,ty,pos;
if (x > tmp[len])
{
if (s[len][len] >= C) return true;
else return false;
}
pos = upper_bound(tmp+,tmp+len+,tmp[len]-x+) - tmp - ;
for (i = ; i <= pos; i++)
{
for (j = ; j <= pos; j++)
{
tx = upper_bound(tmp+,tmp+len+,tmp[i]+x-) - tmp - ;
ty = upper_bound(tmp+,tmp+len+,tmp[j]+x-) - tmp - ;
if (getsum(i,j,tx,ty) >= C) return true;
}
}
return false;
} int main()
{ scanf("%d%d",&C,&N);
for (i = ; i <= N; i++)
{
scanf("%d%d",&x[i],&y[i]);
tmp[++len] = x[i];
tmp[++len] = y[i];
}
sort(tmp+,tmp+len+);
len = unique(tmp+,tmp+len+) - tmp - ;
for (i = ; i <= N; i++)
{
tx = lower_bound(tmp+,tmp+len+,x[i]) - tmp;
ty = lower_bound(tmp+,tmp+len+,y[i]) - tmp;
s[tx][ty]++;
}
tmp[++len] = ;
for (i = ; i <= len; i++)
{
for (j = ; j <= len; j++)
{
s[i][j] = s[i-][j] + s[i][j-] - s[i-][j-] + s[i][j];
}
}
l = ; r = ;
while (l <= r)
{
mid = (l + r) >> ;
if (check(mid))
{
r = mid - ;
ans = mid;
} else l = mid + ;
}
printf("%d\n",ans); return ; }

【POJ 3179】 Corral the Cows的更多相关文章

  1. 【POJ - 2387】Til the Cows Come Home(最短路径 Dijkstra算法)

    Til the Cows Come Home 大奶牛很热爱加班,他和朋友在凌晨一点吃完海底捞后又一个人回公司加班,为了多加班他希望可以找最短的距离回到公司.深圳市里有N个(2 <= N < ...

  2. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  3. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  4. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  5. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  6. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  7. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  8. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

  9. BZOJ2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 513  Solved: 201[Submit][ ...

随机推荐

  1. maven 项目转 gradle

    打开maven 项目的根目录,CMD 执行命令:gradle init --type pom maven项目就变成了gradle项目

  2. BZOJ-5424: 烧桥计划(单调队列)

    BZOJ-5424: 烧桥计划(单调队列) 题目链接 题解: 先考虑最暴力的\(dp\):设\(f[k][i]\)表示搞掉第\(1\sim i\)段,烧了\(k\)段的最小花费,设\(calc(x,y ...

  3. 关于angularJS的$watch的 一些小用法

    $watch方法,它可以帮助我们在每个scope中监视其中的变量. $watch 单一的变量 对于普通的变量时,如数字,字符串等,直接如下写是可以监视到变量的变化,并执行相应的函数的. $scope. ...

  4. python学习笔记(excel+unittest)

    准备先利用之前整理的python自带的unittest框架 整合excel 实现接口自动化测试功能 先看看excel表格设置: 下来是对excel获取的代码: #!/usr/bin/env pytho ...

  5. JS获取元素计算过后的样式

    获取元素计算过后的样式 Window.getComputedStyle() 方法会在一个元素应用完有效样式且计算完所有属性的基本值之后给出所有 CSS 属性的值. 语法: let style = wi ...

  6. python函数式编程之返回函数、匿名函数、装饰器、偏函数学习

    python函数式编程之返回函数 高阶函数处理可以接受函数作为参数外,还可以把函数作为结果值返回. 函数作为返回值 def laxy_sum(*args): def sum(): ax = 0; fo ...

  7. 解析session与cookie

    Session和Cookie相关概念 Session和Cookie都是有服务器生成的. Session和Cookie都是键值对形式保存,主要用于存储特定的一些状态值. Session保存在服务器,Co ...

  8. 51nod 1119 组合数,逆元

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1119 1119 机器人走方格 V2 基准时间限制:1 秒 空间限制:13 ...

  9. python基础8之类的实例化过程剖析

    一.概述 之前我们说关于python中的类,都一脸懵逼,都想说,类这么牛逼到底是什么,什么才是类?下面我们就来讲讲,什么是类?它具有哪些特性. 二.类的语法 2.1 语法 class dog(obje ...

  10. 29-THREE.JS 根据公式画形状

    <!DOCTYPE html> <html> <head> <title></title> <script src="htt ...