当前位置: 首页 > news >正文

洛谷——P2862 [USACO06JAN]把牛Corral the Cows

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()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',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)
{
    if(r-l+1<c) return false;
    int sum=0;
    for(int i=l;i<=r;i++)
     tmp[++sum]=node[i].y;
    sort(tmp+1,tmp+1+sum);
    for(int i=c;i<=sum;i++)
     if(tmp[i]-tmp[i-c+1]<=mid) return true;
    return false;
}
int pd(int x)
{
    int l=1,r;
    for(r=1;r<=n;r++)
    {
        if(node[r].x-node[l].x>x) 
        {
            if(work(l,r-1)) 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();
    for(int i=1;i<=n;i++)
     node[i].x=read(),node[i].y=read();
    sort(node+1,node+1+n,cmp);
    int L=0,R=10000;
    while(L<=R)
    {
        mid=(L+R)>>1;
        if(pd(mid)) ans=mid+1,R=mid-1;
        else L=mid+1;
    }
    printf("%d",ans);
    return 0; 
}

 

 

             

 

 

                      距 NOIp2017 还剩 16 天

 

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

转载于:https://www.cnblogs.com/z360/p/7732121.html

相关文章:

  • web开发经验
  • Zookeeper+ActiveMQ 集群实现
  • Android 使用DDMS查看内存使用情况
  • 新品牌如何开展网络营销?
  • 什么是自动化运维 ? 自动化运维的设计思路以及实战
  • 1.3给定两个字符串,请编写程序,确定其中一个字符串的字符重新排列后,能否变成另一个字符串。...
  • html+css+JavaScript例题
  • 通过递归的方式将字符串逆置打印
  • Oracle osw监控工具的使用示例
  • ASP.NET 跨平台应用开发
  • linux负载查看
  • 【漫谈数据仓库】 如何优雅地设计数据分层
  • Last_SQL_Errno: 1366
  • 那些年困扰我们的委托(C#)
  • 解决发邮件出现“501 Domain address required: HELO”问题
  • 2019.2.20 c++ 知识梳理
  • ECMAScript 6 学习之路 ( 四 ) String 字符串扩展
  • Javascript编码规范
  • JS 面试题总结
  • MQ框架的比较
  • SpingCloudBus整合RabbitMQ
  • Spring Cloud Alibaba迁移指南(一):一行代码从 Hystrix 迁移到 Sentinel
  • SpringBoot几种定时任务的实现方式
  • Work@Alibaba 阿里巴巴的企业应用构建之路
  • 前端面试总结(at, md)
  • 深度解析利用ES6进行Promise封装总结
  • 正则与JS中的正则
  • ​力扣解法汇总946-验证栈序列
  • #13 yum、编译安装与sed命令的使用
  • (1/2)敏捷实践指南 Agile Practice Guide ([美] Project Management institute 著)
  • (ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY)讲解
  • (动手学习深度学习)第13章 计算机视觉---微调
  • (二)Pytorch快速搭建神经网络模型实现气温预测回归(代码+详细注解)
  • (论文阅读11/100)Fast R-CNN
  • (转)http-server应用
  • (转)Sql Server 保留几位小数的两种做法
  • (转)Sublime Text3配置Lua运行环境
  • (转)Unity3DUnity3D在android下调试
  • (转载)CentOS查看系统信息|CentOS查看命令
  • (最简单,详细,直接上手)uniapp/vue中英文多语言切换
  • **CI中自动类加载的用法总结
  • .Net调用Java编写的WebServices返回值为Null的解决方法(SoapUI工具测试有返回值)
  • :=
  • ??myeclipse+tomcat
  • @JoinTable会自动删除关联表的数据
  • [ 隧道技术 ] cpolar 工具详解之将内网端口映射到公网
  • []指针
  • [《百万宝贝》观后]To be or not to be?
  • [acwing周赛复盘] 第 69 场周赛20220917
  • [AIGC] Spring Interceptor 拦截器详解
  • [BZOJ1010] [HNOI2008] 玩具装箱toy (斜率优化)
  • [BZOJ1877][SDOI2009]晨跑[最大流+费用流]
  • [C#]获取指定文件夹下的所有文件名(递归)
  • [C/C++] C/C++中数字与字符串之间的转换
  • [C++] new和delete