问题 Z: 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.
输入
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.
样例输入
复制样例数据
3 4 1 2 2 1 4 1 5 2
样例输出
4
提示
|* *
| * *
+------
Below is one 4x4 solution (C's show most of the corral's area); many others exist.
|CCCC
|CCCC
|*CCC*
|C*C*
+------
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int C,N,mid,jg,tp[10010];
struct node
{int x;int y;
} p[10010];
int cmp(node a,node b)
{return a.x<b.x;
}
int qz(int l,int r)
{if(r-l+1<C)return 0;int ct=0;for(int i=l; i<=r; i++)tp[++ct]=p[i].y;sort(tp+1,tp+ct+1);for(int i=C; i<=ct; i++)if(tp[i]-tp[i-C+1]<=mid)return 1;return 0;
}
int pd(int x)
{int l=1,i;for(int i=1; i<=N; i++){if(p[i].x-p[l].x>x){if(qz(l,i-1))return 1;while(p[i].x-p[l].x>x)l++;}}if(qz(l,N))return 1;return 0;
}
int main()
{
// cin>>C>>N;scanf("%d%d",&C,&N);for(int i=1; i<=N; i++)scanf("%d%d",&p[i].x,&p[i].y);sort(p+1,p+N+1,cmp);int l=0,r=10000;while(l<=r){mid=(l+r)/2;if(pd(mid)){jg=mid+1;r=mid-1;}elsel=mid+1;}printf("%d\n",jg);return 0;
}
问题 Z: Corral the Cows(二分,分治)相关推荐
- Corral the Cows(二分、前缀和、离散化)
题面:Corral the Cows[牛客] 题目大意 有 nnn 个单位的三叶草,每单位三叶草占据一个 1×11×11×1 的土地,每块土地的位置由其左下角的下标确定,并且下标 xxx 和 yyy ...
- POJ - 3179 Corral the Cows(二分,离散化,前缀和)
POJ - 3179 Corral the Cows #include<iostream> #include<vector> #include<algorithm> ...
- 洛谷——P2862 [USACO06JAN]把牛Corral the Cows
P2862 [USACO06JAN]把牛Corral the Cows 题目描述 Farmer John wishes to build a corral for his cows. Being fi ...
- 洛谷 P2862 [USACO06JAN]把牛Corral the Cows 解题报告
P2862 [USACO06JAN]把牛Corral the Cows 题目描述 Farmer John wishes to build a corral for his cows. Being fi ...
- 洛谷P2862 [USACO06JAN]把牛Corral the Cows
P2862 [USACO06JAN]把牛Corral the Cows 题目描述 Farmer John wishes to build a corral for his cows. Being fi ...
- 洛谷 P2862 [USACO06JAN]把牛Corral the Cows
P2862 [USACO06JAN]把牛Corral the Cows 题目描述 Farmer John wishes to build a corral for his cows. Being fi ...
- POJ - 3179 Corral the Cows(离散化+二分+二维前缀和)
题目链接:点击查看 题目大意:在二维平面中给出n个点,每个位置都有一个一个三叶草,现在需要求出一个长方形区域,要求长方形边长最短,并且面积内部包含至少C个三叶草 题目分析:题目给出的n最大为500,但 ...
- poj3179 Corral the Cows(二分, 前缀和, 离散化, 双指针)
题目描述 农夫约翰希望为他的奶牛们建立一个畜栏. 这些挑剔的畜生要求畜栏必须是正方形的,而且至少要包含C单位的三叶草,来当做它们的下午茶. 畜栏的边缘必须与X,Y轴平行. 约翰的土地里一共包含N单位的 ...
- POJ3179 Corral the Cows 离散化 二分 前缀和
题目链接 http://poj.org/problem?id=3179 分析 容易想到二分和前缀和,难点在于坐标离散化,要将横纵坐标分别离散化. 对于三叶草的每个坐标,将其映射为次序: 没有三叶草的位 ...
最新文章
- android EditText监听事件及参数详解
- CodeForce 463C Gargari and Bishops(贪心+暴力)
- 供应链 信用管理 大数据_以“大数据”引领农产品供应链变革,推动农产品供应链智能化发展...
- Sql日期时间格式转换
- 第八届“图灵杯”NEUQ-ACM程序设计竞赛个人赛——D题 Seek the Joker I
- asp.net生产环境和开发环境的错误日志包装策略
- silk lobe资源公众号_微小说全免费阅读公众号阅读网资源推荐
- python的拼音_Python之拼音拆分
- 疫情下的美国娱乐业 | 游戏里的演唱会引千万人参加, 你会买票吗?
- 这么选家用投影仪,再也不交智商税
- oracle忘记密码找回
- Windows10常用快捷键+cmd常见命令码
- 单片机——8位数码管循环显示0-7
- NiFi Processors之PutSQL
- 艾永亮:巴奴火锅的自救与救他计划,超级产品战略打响门店保卫战
- 记一次tomcat报错 系统找不到指定路径
- matlab求表达式绝对值,matlab绝对值怎么表示
- 物联网 探秘零售业的“芯”机遇
- java stream collect_java stream流中的collect()方法详解
- 人工智能在医疗保健服务演变中的作用越来越大
热门文章
- 一千万条数据去重_DB2千万级数据去重
- 大数据基础环境搭建的从spark到hadoop,从底层硬件到上层软件的一些必备注意事项
- Hadoop分布式集群搭建完全详细教程
- 2014-01-14
- pyqt5 日历设计 QSS
- 中俄边城“丝路欢聚”共庆中国年
- 南大通用GBase8s 常用SQL语句(120) DISCONNECT 语句
- IBM 的另一面http://www-31.ibm.com/innovation/cn/iter/2011v17/
- AFC中央计算机系统图,干货丨城市地铁AFC系统由哪些部分组成的?如何运作?
- 安全学院“传承文化”暑期实践团对大明宫国家遗址公园、大华博物馆展开调研