题目描述

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.

输入输出样例

输入样例#1: 复制

6
J*J***
******
J***J*
******
**B***
******
输出样例#1: 复制

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的更多相关文章

  1. 洛谷P2867 [USACO06NOV]大广场Big Square

    P2867 [USACO06NOV]大广场Big Square 题目描述 Farmer John's cows have entered into a competition with Farmer ...

  2. 洛谷P1879 [USACO06NOV]玉米田Corn Fields(状压dp)

    洛谷P1879 [USACO06NOV]玉米田Corn Fields \(f[i][j]\) 表示前 \(i\) 行且第 \(i\) 行状态为 \(j\) 的方案总数.\(j\) 的大小为 \(0 \ ...

  3. 洛谷 P1230 智力大冲浪

    洛谷 P1230 智力大冲浪 题目描述 小伟报名参加中央电视台的智力大冲浪节目.本次挑战赛吸引了众多参赛者,主持人为了表彰大家的勇气,先奖励每个参赛者m元.先不要太高兴!因为这些钱还不一定都是你的?! ...

  4. 洛谷 P6218 [USACO06NOV] Round Numbers S

    洛谷 P6218 [USACO06NOV] Round Numbers S 题目描述 如果一个正整数的二进制表示中,\(0\) 的数目不小于 \(1\) 的数目,那么它就被称为「圆数」. 例如,\(9 ...

  5. 洛谷P2866 [USACO06NOV]糟糕的一天Bad Hair Day

    P2866 [USACO06NOV]糟糕的一天Bad Hair Day 75通过 153提交 题目提供者洛谷OnlineJudge 标签USACO2006云端 难度普及/提高- 时空限制1s / 12 ...

  6. 洛谷P3348 [ZJOI2016]大森林(LCT,虚点,树上差分)

    洛谷题目传送门 思路分析 最简单粗暴的想法,肯定是大力LCT,每个树都来一遍link之类的操作啦(T飞就不说了) 考虑如何优化算法.如果没有1操作,肯定每个树都长一样.有了1操作,就来仔细分析一下对不 ...

  7. 【题解】洛谷P1879 [USACO06NOV] Corn Fields(状压DP)

    洛谷P1879:https://www.luogu.org/problemnew/show/P1879 思路 把题目翻译成人话 在n*m的棋盘 每个格子不是0就是1 1表示可以种 0表示不能种 相邻的 ...

  8. 洛谷——P2865 [USACO06NOV]路障Roadblocks

    P2865 [USACO06NOV]路障Roadblocks 题目描述 Bessie has moved to a small farm and sometimes enjoys returning ...

  9. 洛谷 P1879 [USACO06NOV]玉米田Corn Fields 题解

    P1879 [USACO06NOV]玉米田Corn Fields 题目描述 Farmer John has purchased a lush new rectangular pasture compo ...

随机推荐

  1. [转载]-分布式之redis复习精讲

    原创地址:https://www.cnblogs.com/rjzheng/p/9096228.html 看这篇文章前,我看的是另一个人博客上的文章.看到最后(评论这一块)很多人就指出这并非原创而是抄袭 ...

  2. linux一个网卡添加多个虚IP

    [root@localhost ~]# ifconfig bond0:0 10.0.0.202 netmask 255.255.255.255 broadcast 10.0.0.255 up 摘自:h ...

  3. 05-数据类型转换(bool类型)

  4. 【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) C】 Permutation Cycle

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] p[i] = p[p[i]]一直进行下去 在1..n的排列下肯定会回到原位置的. 即最后会形成若干个环. g[i]显然等于那个环的大 ...

  5. hdu 4707 Pet【BFS求树的深度】

    Pet                                                          Time Limit: 4000/2000 MS (Java/Others)  ...

  6. uip UDP server广播模式(client能够随意port,而且主动向client发送数据)

    眼下移植uip,发现UDP server模式下,必须指定本地port以及clientport,否则仅仅能讲clientport设置为0,才干接收随意port的数据,可是无法发送数据,由于此时clien ...

  7. Android View体系(九)自定义View

    相关文章 Android View体系(一)视图坐标系 Android View体系(二)实现View滑动的六种方法 Android View体系(三)属性动画 Android View体系(四)从源 ...

  8. POJ 1636 DFS+DP

    思路: 先搜索出来如果选这个点 其它哪些点必须选 跑个背包就好了 //By SiriusRen #include <cstdio> #include <cstring> #in ...

  9. 设计兼容不同的屏幕尺寸的Android界面

    Android的屏幕类型有几百种不同的尺寸,从小型的手机到大型的电视机.因此要使我们的应用程序兼容不同屏幕尺寸,才可以让我们的应用提供给更多的用户使用. 一.支持不同的屏幕尺寸 1.使用"w ...

  10. installp 软件的4种状态

    安装和维护LPP软件     installp 对包提供了如下四种主要的操作: Apply Commit Reject Remove   webes.4.0.0.1 commited webes.4. ...