POJ3179 Corral the Cows题解
我就是个垃圾……一道水题能写这么长时间……
首先看到题就想到了二维前缀和+二分边长,但地图边长10000,得离散化。
于是这个离散化就把我搞疯了,淦。
这反映出现在基础知识还是不牢固,相当不牢固。
复杂度不会算,淦。(但应该不会超过\(O(C^2\log N)\)
具体看代码吧……
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct P{int x,y;}a[505];
int c,n,dx,dy,xx[10005],yy[10005];
int x[505],y[505],s[505][505];
bool check(int k)
{
for(int i=xx[k];i<=dx;++i) //如果边长是k,那么从k的不同的数开始找起
for(int j=yy[k];j<=dy;++j)
{
int x0=0,y0=0;
if(x[i]-k>=0) x0=xx[x[i]-k]; //这里是一个映射原坐标的判断,这样的对应应该是没问题的
if(y[j]-k>=0) y0=yy[y[j]-k];
if(s[i][j]-s[x0][j]-s[i][y0]+s[x0][y0]>=c) return 1;
}
return 0;
}
int main()
{
scanf("%d%d",&c,&n);
for(int i=1;i<=n;++i)
{
scanf("%d%d",&a[i].x,&a[i].y);
xx[a[i].x]++,yy[a[i].y]++; //这是开了个桶
}
for(int i=1;i<=10000;++i)
{
if(xx[i]) x[++dx]=i; //如果这个桶有值,那么就把它扔进一个映射的数组里
xx[i]=dx; //可以发现x与xx是互为逆运算的,也就是x[i]表示第i个不同的数是几,
//xx[i]表示i这个数是第几个不同的数
if(yy[i]) y[++dy]=i;
yy[i]=dy;
}
for(int i=1;i<=n;++i) s[xx[a[i].x]][yy[a[i].y]]++; //我们用编号来做前缀和
for(int i=1;i<=dx;++i)
for(int j=1;j<=dy;++j)
s[i][j]+=s[i-1][j]+s[i][j-1]-s[i-1][j-1];
int l=1,r=10000,ans;
while(l<=r)
{
int mid=l+r>>1;
if(check(mid)) ans=mid,r=mid-1;
else l=mid+1;
}
printf("%d",ans);
return 0;
}
POJ3179 Corral the Cows题解的更多相关文章
- poj3179 Corral the Cows
论水题与难题的差距:在于一个upper_bound 那么,这题一看就很显然了:因为答案满足二分性质所以我们二分. 然后我们再建造一个二维前缀和,每次判断的时候怎么办呢? 我先以为是贪心:选择以每个点为 ...
- $Poj3179\ Corral\ the\ Cows$ 二分+离散化+二维前缀和
Poj $Description$ 在一个二维平面上,有$N$颗草,每颗草的大小是$1*1$,左下角坐标为$x_i,y_i$.要求一个正方形,正方形的边平行于$x$或$y$轴,正方形里面包含至少$C$ ...
- 【BZOJ1720】[Usaco2006 Jan]Corral the Cows 奶牛围栏 双指针法
[BZOJ1720][Usaco2006 Jan]Corral the Cows 奶牛围栏 Description Farmer John wishes to build a corral for h ...
- POJ 3179 Corral the Cows
Corral the Cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1352 Accepted: 565 De ...
- 洛谷 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 ...
- POJ2182 Lost Cows 题解
POJ2182 Lost Cows 题解 描述 有\(N\)(\(2 <= N <= 8,000\))头母牛,每头母牛有自己的独一无二编号(\(1..N\)). 现在\(N\)头母牛站成一 ...
随机推荐
- [论文阅读笔记] Adversarial Mutual Information Learning for Network Embedding
[论文阅读笔记] Adversarial Mutual Information Learning for Network Embedding 本文结构 解决问题 主要贡献 算法原理 实验结果 参考文献 ...
- 【NX二次开发】拉伸的偏置方向猜想与验证
结论:偏置的方向为曲线方向与拉伸方向的向量叉乘. 在UF_MODL_create_extrusion帮助中有这么一句话:Note that the offset direction is determ ...
- 【NX二次开发】移动WCS坐标系
说明:移动WCS坐标系 用法: #include <uf.h> #include <uf_csys.h> extern DllExport void ufusr(char *p ...
- 关于web移动端定位
最近在做一个搜索附近3公里所有超市信息(已经录入数据库的超市信息)的功能.思路很简单只是获取用户当前地理位置(经纬度),通过sql语句筛选出3公里范围内的所有超市信息,然后传递到前台页面展示出来.但是 ...
- Linux命令大全之挂载命令
理解:Linux挂载相当于Windows分配盘符 1.查询系统中已挂载的设备 mount 2.设置自动挂载 编辑文件/etc/fstab,把文件写入就可以启动自动挂载了, 注:一般不把光盘写入,如果写 ...
- Auto.js无障碍免root脚本开发学习
Auto.js 简单入门 官方文档:https://hyb1996.github.io/AutoJs-Docs/#/ https://blog.csdn.net/QiHsMing/article/de ...
- 关于Kubernetes(简称K8S)的开启及基本使用,基于Docker Desktop & WSL2
背景介绍 Kubernetes(简称k8s)已成为目前业界容器编排的事实标准,其搭配Docker可建立非常高效便捷的高可扩展.高可用应用服务架构. Kubernetes的名字来自希腊语,意思是&quo ...
- 8、linux常用命令
8.1.pwd: 显示当前的路径: -L:显示逻辑路径,即快捷方式的路径(默认的参数): -P :显示物理路径,真实的路径: 8.2.man: 命令的查看: 8.3.help: 命令的查看: 8.4. ...
- 11、mysql索引详解
1.索引介绍: 2.建立索引的方法: 注意:索引名称不要相同: (1)在建表的时候,可以增加主键索引的语句如下: 1)例一: create table student1 ( id int(4) not ...
- Burning Bridges 求tarjan求割边
Burning Bridges 给出含有n个顶点和m条边的连通无向图,求出所有割边的序号. 1 #include <cstdio> 2 #include <cstring> 3 ...