洛谷 P2867 [USACO06NOV]大广场Big Square
题目描述
Farmer John's cows have entered into a competition with Farmer Bob's cows. They have drawn lines on the field so it is a square grid with N × N points (2 ≤ N ≤ 100), and each cow of the two herds has positioned herself exactly on a gridpoint. Of course, no two cows can stand in the same gridpoint. The goal of each herd is to form the largest square (not necessarily parallel to the gridlines) whose corners are formed by cows from that herd.
All the cows have been placed except for Farmer John's cow Bessie. Determine the area of the largest square that Farmer John's cows can form once Bessie is placed on the field (the largest square might not necessarily contain Bessie).
农民 John 的牛参加了一次和农民 Bob 的牛的竞赛。他们在区域中画了一个N*N 的正方形点阵,两个农场的牛各自占据了一些点。当然不能有两头牛处于同一个点。农场的目标是用自己的牛作为4个顶点,形成一个面积最大的正方形(不必须和边界平行) 。 除了 Bessie 以外,FJ其他的牛都已经放到点阵中去了,要确定bessie放在哪个位置,能使得农民约翰的农场得到一个最大的正方形(Bessie不是必须参与作为正方形的四个顶点之一)。
输入输出格式
输入格式:
Line 1: A single integer, N
Lines 2..N+1: Line i+1 describes line i of the field with N characters. The characters are: 'J' for a Farmer John cow, 'B' for a Farmer Bob cow, and '*' for an unoccupied square. There will always be at least one unoccupied gridpoint.
输出格式:
Line 1: The area of the largest square that Farmer John's cows can form, or 0 if they cannot form any square.
输入输出样例
6
J*J***
******
J***J*
******
**B***
******
4
思路:暴力枚举对角线上的两个点,然后计算出中点坐标。
然后可以根据平面向量计算出其余的两个对角线的坐标。
判断是否合法即可,如果可以就取最大值。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 10000
using namespace std;
char s[];
int n,num,ans;
int map[][];
struct nond{
double x,y;
}cnt[MAXN];
bool dint(double x,int y){
return y-0.001<=x and x<=y+0.001;
}
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%s",s+);
for(int j=;j<=n;j++){
if(s[j]=='B') map[i][j]=;
else if(s[j]=='J'){
map[i][j]=;
cnt[++num].x=i;
cnt[num].y=j;
}
}
}
for(int i=;i<=num;i++)
for(int j=i+;j<=num;j++){
double midx=(cnt[i].x+cnt[j].x)/2.0;//中点
double midy=(cnt[i].y+cnt[j].y)/2.0;//中点
double mx=(cnt[i].x-cnt[j].x)/2.0; //向量
double my=(cnt[i].y-cnt[j].y)/2.0; //向量
double dx=midx+(-my);
double dy=midy+mx;
if(dx<||dx>n) continue;
if(dy<||dy>n) continue;
double wx=midx+my;
double wy=midy+(-mx);
if(wx<||wx>n) continue;
if(wy<||wy>n) continue;
if(dx==wx&&dy==wy) continue;
int ax=int(dx+0.5),ay=int(dy+0.5);
int bx=int(wx+0.5),by=int(wy+0.5);
if(!dint(dx,ax)) continue;
if(!dint(dy,ay)) continue;
if(!dint(wx,bx)) continue;
if(!dint(wy,by)) continue;
if(map[ax][ay]==||map[bx][by]==) continue;
if(!map[ax][ay]&&!map[bx][by]) continue;
int S=(dx-cnt[i].x)*(dx-cnt[i].x)+(dy-cnt[i].y)*(dy-cnt[i].y);
ans=max(ans,S);
}
cout<<ans;
}
洛谷 P2867 [USACO06NOV]大广场Big Square的更多相关文章
- 洛谷P2867 [USACO06NOV]大广场Big Square
P2867 [USACO06NOV]大广场Big Square 题目描述 Farmer John's cows have entered into a competition with Farmer ...
- 洛谷P1879 [USACO06NOV]玉米田Corn Fields(状压dp)
洛谷P1879 [USACO06NOV]玉米田Corn Fields \(f[i][j]\) 表示前 \(i\) 行且第 \(i\) 行状态为 \(j\) 的方案总数.\(j\) 的大小为 \(0 \ ...
- 洛谷 P1230 智力大冲浪
洛谷 P1230 智力大冲浪 题目描述 小伟报名参加中央电视台的智力大冲浪节目.本次挑战赛吸引了众多参赛者,主持人为了表彰大家的勇气,先奖励每个参赛者m元.先不要太高兴!因为这些钱还不一定都是你的?! ...
- 洛谷 P6218 [USACO06NOV] Round Numbers S
洛谷 P6218 [USACO06NOV] Round Numbers S 题目描述 如果一个正整数的二进制表示中,\(0\) 的数目不小于 \(1\) 的数目,那么它就被称为「圆数」. 例如,\(9 ...
- 洛谷P2866 [USACO06NOV]糟糕的一天Bad Hair Day
P2866 [USACO06NOV]糟糕的一天Bad Hair Day 75通过 153提交 题目提供者洛谷OnlineJudge 标签USACO2006云端 难度普及/提高- 时空限制1s / 12 ...
- 洛谷P3348 [ZJOI2016]大森林(LCT,虚点,树上差分)
洛谷题目传送门 思路分析 最简单粗暴的想法,肯定是大力LCT,每个树都来一遍link之类的操作啦(T飞就不说了) 考虑如何优化算法.如果没有1操作,肯定每个树都长一样.有了1操作,就来仔细分析一下对不 ...
- 【题解】洛谷P1879 [USACO06NOV] Corn Fields(状压DP)
洛谷P1879:https://www.luogu.org/problemnew/show/P1879 思路 把题目翻译成人话 在n*m的棋盘 每个格子不是0就是1 1表示可以种 0表示不能种 相邻的 ...
- 洛谷——P2865 [USACO06NOV]路障Roadblocks
P2865 [USACO06NOV]路障Roadblocks 题目描述 Bessie has moved to a small farm and sometimes enjoys returning ...
- 洛谷 P1879 [USACO06NOV]玉米田Corn Fields 题解
P1879 [USACO06NOV]玉米田Corn Fields 题目描述 Farmer John has purchased a lush new rectangular pasture compo ...
随机推荐
- 2019 前端面试题汇总(主要为 Vue)
原文链接:点我 由于我的技术栈主要为Vue,所以大部分题目都是Vue开发相关的. 1. 谈谈你对MVVM开发模式的理解 MVVM分为Model.View.ViewModel三者. Model:代表数据 ...
- 为什么使用Nginx & Nginx的使用
Nginx在Windows平台的配置: 什么是Nginx? 根据前面的对比,我们可以了解到Nginx是一个http服务器.是一个使用c语言开发的高性能的http服务器及反向代理服务器.Nginx是一款 ...
- caioj 1069 动态规划入门(二维一边推2:顺序对齐)(最长公共子序列拓展总结)
caioj 1068是最长公共子序列裸体,秒过, 就不写博客了 caioj 1069到1071 都是最长公共字序列的拓展,我总结出了一个模型,屡试不爽 (1) 字符串下标从1开始,因为0用来表示 ...
- java回调方法、钩子方法以及模板方法模式
在面向对象的语言中,回调则是通过接口或抽象类来实现的,我们把实现这种接口的类称为回调类,回调类的对象称为回调对象,其处理事件的方法叫做回调方法.(摘自百度百科) 那么通过上面那句话将百度百科中的&qu ...
- HDU 4183Pahom on Water(网络流之最大流)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4183 这题题目意思非常难看懂..我看了好长时间也没看懂..终于是从网上找的翻译. .我就在这翻译一下吧 ...
- Gym - 100637A Nano alarm-clocks 模拟
题意:有n个时钟,只能顺时针拨,问使所有时间相同的最小代价是多少 思路:将时间排序,枚举拨动到每一个点的时间就好了,容易证明最终时间一定是其中之一 #include <iostream> ...
- K-序列(埃森哲杯第十六届上海大学程序设计联赛春季赛暨上海高校金马五校赛)
题目描述 给一个数组 a,长度为 n,若某个子序列中的和为 K 的倍数,那么这个序列被称为“K 序列”.现在要你 对数组 a 求出最长的子序列的长度,满足这个序列是 K 序列. 输入描述: 第一行为 ...
- Assembly.Load 详解(c#)
我们在使用C# 语言的Assembly.Load 来加载托管程序集并使用反射功能时,一般需要先通过Assembly.Load(), Assembly.LoadFrom() 等方法将目标托管程序集加载到 ...
- angularjs 页面缓存及动态刷新解决方案
一.准备工作 框架:angularjs ui组件库:ionic1 二.页面缓存cache 路由设置cache参数,true为缓存,false为不缓存,代码如下: angular.module('app ...
- 【Docker入门】
目录 Linux容器 Docker的优势 Docker三大概念 安装使用Docker 补充知识 [Docker入门] 发布文章 "qq_41964425" @ *** 所谓Dock ...