P2862 [USACO06JAN]把牛Corral the Cows

题目描述

Farmer John wishes to build a corral for his cows. Being finicky beasts, they demand that the corral be square and that the corral contain at least C (1 <= C <= 500) clover fields for afternoon treats. The corral's edges must be parallel to the X,Y axes.

FJ's land contains a total of N (C <= N <= 500) clover fields, each a block of size 1 x 1 and located at with its lower left corner at integer X and Y coordinates each in the range 1..10,000. Sometimes more than one clover field grows at the same location; such a field would have its location appear twice (or more) in the input. A corral surrounds a clover field if the field is entirely located inside the corral's borders.

Help FJ by telling him the side length of the smallest square containing C clover fields.

约翰打算建一个围栏来圈养他的奶牛.作为最挑剔的兽类,奶牛们要求这个围栏必须是正方 形的,而且围栏里至少要有C< 500)个草场,来供应她们的午餐.

约翰的土地上共有C<=N<=500)个草场,每个草场在一块1x1的方格内,而且这个方格的 坐标不会超过10000.有时候,会有多个草场在同一个方格内,那他们的坐标就会相同.

告诉约翰,最小的围栏的边长是多少?

输入输出格式

输入格式:

Line 1: Two space-separated integers: C and N

Lines 2..N+1: Each line contains two space-separated integers that are the X,Y coordinates of a clover field.

输出格式:

Line 1: A single line with a single integer that is length of one edge of the minimum size square that contains at least C clover fields.

输入输出样例

输入样例#1: 复制

3 4
1 2
2 1
4 1
5 2
输出样例#1: 复制

4

说明

Explanation of the sample:

|* *

| * *

+------Below is one 4x4 solution (C's show most of the corral's area); many others exist.

|CCCC

|CCCC

|*CCC*

|C*C*

+------

什么?!这道题做过?!啊啊啊、、、蒟蒻表示忘记了、、、

http://www.cnblogs.com/z360/p/7641389.html

二分答案

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 5010
using namespace std;
int c,n,mid,ans,tmp[N];
int read()
{
    ,f=;char ch=getchar();
    ;ch=getchar();}
    +ch-',ch=getchar();
    return x*f;
}
struct Node
{
    int x,y;
}node[N];
int cmp(Node a,Node b){return a.x<b.x;}
int work(int l,int r)
{
    <c) return false;
    ;
    for(int i=l;i<=r;i++)
     tmp[++sum]=node[i].y;
    sort(tmp+,tmp++sum);
    for(int i=c;i<=sum;i++)
     ]<=mid) return true;
    return false;
}
int pd(int x)
{
    ,r;
    ;r<=n;r++)
    {
        if(node[r].x-node[l].x>x)
        {
            )) return true;
            while(node[r].x-node[l].x>x) l++;
        }
    }
    if(work(l,n)) return true;
    return false;
}
int main()
{
    c=read(),n=read();
    ;i<=n;i++)
     node[i].x=read(),node[i].y=read();
    sort(node+,node++n,cmp);
    ,R=;
    while(L<=R)
    {
        mid=(L+R)>>;
        ,R=mid-;
        ;
    }
    printf("%d",ans);
    ;
}

             

                      距 NOIp2017 还剩 16 天

                        你可以做的事情还有很多,即使到最后一秒也不要放弃,因为不到结束的那一刻谁也不知道结果会怎样

洛谷——P2862 [USACO06JAN]把牛Corral the Cows的更多相关文章

  1. 洛谷 P2862 [USACO06JAN]把牛Corral the Cows 解题报告

    P2862 [USACO06JAN]把牛Corral the Cows 题目描述 Farmer John wishes to build a corral for his cows. Being fi ...

  2. 洛谷P2862 [USACO06JAN]把牛Corral the Cows

    P2862 [USACO06JAN]把牛Corral the Cows 题目描述 Farmer John wishes to build a corral for his cows. Being fi ...

  3. 洛谷 P2862 [USACO06JAN]把牛Corral the Cows

    P2862 [USACO06JAN]把牛Corral the Cows 题目描述 Farmer John wishes to build a corral for his cows. Being fi ...

  4. 洛谷[USACO06JAN]把牛Corral the Cows

    题目描述 约翰打算建一个围栏来圈养他的奶牛.作为最挑剔的兽类,奶牛们要求这个围栏必须是正方 形的,而且围栏里至少要有C< 500)个草场,来供应她们的午餐. 约翰的土地上共有C<=N< ...

  5. [luoguP2862] [USACO06JAN]把牛Corral the Cows(二分 + 乱搞)

    传送门 可以二分边长 然后另开两个数组,把x从小到大排序,把y从小到大排序 枚举x,可以得到正方形的长 枚举y,看看从这个y开始,往上能够到达多少个点,可以用类似队列来搞 其实发现算法的本质之后,x可 ...

  6. 洛谷P1522 [USACO2.4]牛的旅行 Cow Tours

    洛谷P1522 [USACO2.4]牛的旅行 Cow Tours 题意: 给出一些牧区的坐标,以及一个用邻接矩阵表示的牧区之间图.如果两个牧区之间有路存在那么这条路的长度就是两个牧区之间的欧几里得距离 ...

  7. 洛谷——P1821 [USACO07FEB]银牛派对Silver Cow Party

    P1821 [USACO07FEB]银牛派对Silver Cow Party 题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently ...

  8. 洛谷 P2863 [USACO06JAN]牛的舞会The Cow Prom-强连通分量(Tarjan)

    本来分好组之后,就确定好了每个人要学什么,我去学数据结构啊. 因为前一段时间遇到一道题是用Lca写的,不会,就去学. 然后发现Lca分为在线算法和离线算法,在线算法有含RMQ的ST算法,前面的博客也写 ...

  9. 洛谷 P2863 [USACO06JAN]牛的舞会The Cow Prom

    传送门 题目大意:形成一个环的牛可以跳舞,几个环连在一起是个小组,求几个小组. 题解:tarjian缩点后,求缩的点包含的原来的点数大于1的个数. 代码: #include<iostream&g ...

随机推荐

  1. 【Linear Support Vector Machine】林轩田机器学习技法

    首先从介绍了Large_margin Separating Hyperplane的概念. (在linear separable的前提下)找到largest-margin的分界面,即最胖的那条分界线.下 ...

  2. C/C++学习笔记--指针(Pointer)

    定义指针 一般类型: type_name  *  var_name; 例如: int _var = 1555; int * _var_addr=&_var; 一般类型数组类:type_name ...

  3. Python之进程、线程、协程

    进程和线程的目的 进程和线程目的是为了:提高执行效率 现代操作系统比如Mac OS X,UNIX,Linux,Windows等,都是支持“多任务”的操作系统. 什么叫“多任务“呢?简单地说,就是操作系 ...

  4. 《Android权威编程指南(The Big Nerd Ranch Guide)(第二版)》12.4挑战练习

    本书第12章是讲解Dialog.12.4挑战练习是在CriminalIntent项目中,再增加一个TimePickerFragment的对话框fragment.通过在CrimeFragment用户界面 ...

  5. sources.ustc.debian

    deb http://mirrors.ustc.edu.cn/debian/ jessie main contrib non-free deb-src http://mirrors.ustc.edu. ...

  6. Oz 创建Windows2008R2镜像

    此tdl和auto文件只可定义windows disk bus以ide模式启动,不支持virtio. <template> <name>Windows-gushiren< ...

  7. JAVA中的使用Filter过滤器设置字符集

    Filter是什么? Filter不是一个Servlet,它可以叫做Servlet链,它可以用来改变一个request,修改一个response.它虽然不能产生一个response,但可以在一个req ...

  8. PHP可变变量的简单使用

    知识点: 可变变量:简单说就是将一个变量的值用作另外一个变量的命名上,例如$a = 'b';$$a就是$b HTML代码: <!doctype html> <html> < ...

  9. P3456 [POI2007]GRZ-Ridges and Valleys

    题意翻译 给定一个地图,为小朋友想要旅行的区域,地图被分为n*n的网格,每个格子(i,j) 的高度w(i,j)是给定的.若两个格子有公共顶点,那么他们就是相邻的格子.(所以与(i,j)相邻的格子有(i ...

  10. 2.1 Python3.5安装以及爬虫需要的环境配置

    之所以选用Python,是因为对于网络爬虫来说,Python是最好上手的一种语言.本文讲述的安装配置都是基于Windows的环境. 另外我想说的是,文中用到的下载链接尽量官方网站上的下载链接,这是我比 ...