【题目链接】

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. Java设计模式学习之工厂模式

    在Java(或者叫做面向对象语言)的世界中,工厂模式被广泛应用于项目中,也许你并没有听说过,不过也许你已经在使用了.Java 设计模式之工厂模式 简单来说,工厂模式的出现源于增加程序序的可扩展性,降低 ...

  2. NOIP 选择客栈

    描述 丽江河边有n家很有特色的客栈,客栈按照其位置顺序从1到n编号.每家客栈都按照某一种色调进行装饰(总共k种,用整数0~ k-1表示),且每家客栈都设有一家咖啡店,每家咖啡店均有各自的最低消费. 两 ...

  3. JSP实现原理

    JSP全称是Java Server Pages,它和servle技术一样,都是SUN公司定义的一种用于开发动态web资源的技术. 起源: 在很多动态网页中,绝大部分内容都是固定不变的,只有局部内容需要 ...

  4. 搭建 Spring 开发环境

    把以下 jar 包加入到工程的 classpath 下: Spring 的配置文件: 一个典型的 Spring 项目需要创建一个或多个 Bean 配置文件, 这些配置文件用于在 Spring IOC ...

  5. sem学习

    关键字的选取搜索引擎营销的关键字选取是非常重要的一步,合适的关键字可以为企业带来可观的咨询量.关键字一般分4种,品牌词,产品词,行业词,竞品词,对于这四类词不同的推广策略有着不同的侧重点,根据市场情况 ...

  6. js 执行跨域刷新页面

    主要代码: 注意这段代码 是子页面中添加的也就是弹出的那个页面刷新父页面 <script type="text/javascript"> function shuaxi ...

  7. C++ 函数后面的const

    一个函数 AcGePoint3dstartPoint() const; const放在后面跟前面有区别么 ==> 准确的说const是修饰this指向的对象的 譬如,我们定义了 classA{ ...

  8. python基础7 - 函数

    1. 函数的快速体验 所谓函数,就是把 具有独立功能的代码块 组织为一个小模块,在需要的时候 调用 函数的使用包含两个步骤: 定义函数 —— 封装 独立的功能 调用函数 —— 享受 封装 的成果 函数 ...

  9. Java 子类实例化对象的过程

    子类实例化是否会实例化父类? 不会.父类在子类实例化过程中是并没有被实例化,java中new子类没有实例化父类,只是调用父类的构造方法初始化了,子类从父类继承来的属性,这个调用是子类的对象调用的父类的 ...

  10. [java插件]myeclipse添加插件

    在C:\Program Files\MyEclipse 6.0\eclipse\links里建立一个svn.link. svn.link文件内容: path=C:/Program Files/MyEc ...