洛谷P2867 [USACO06NOV]大广场Big Square
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
一开始很困惑样例是怎么来的,看了大神博客附的图就明白了
因为要加一个点,所以当前只需要得到能构成等腰直角三角形的三个点
数据规模100,可以枚举正方形对角线两点的横纵坐标,计算出另外两个点的坐标,当然要保证得出的四个点的坐标都在图内而且不与‘B’重合
每得到一个可行解就更新一遍答案
#include<bits/stdc++.h>
using namespace std;
const int N=;
string mat[N];
int main()
{
int n;
cin>>n;
for(int i=;i<n;i++)
cin>>mat[i];
int ans=;
for(int x1=;x1<n;x1++)
for(int y1=;y1<n;y1++)
{
if(mat[x1][y1]=='B')
continue;
for(int x2=x1;x2<n;x2++)
for(int y2=y1;y2<n;y2++)
{
if(mat[x2][y2]=='B'||(mat[x1][y1]=='.'&&mat[x2][y2]=='.'))
continue;
int dx=x2-x1,dy=y2-y1,x3=x1+dy,y3=y1-dx,x4=x2+dy,y4=y2-dx;
if(x3>=&&x3<n&&y3>=&&y3<n&&x4>=&&x4<n&&y4>=&&y4<n&&mat[x3][y3]!='B'&&mat[x4][y4]!='B'&&(mat[x1][y1]=='J')+(mat[x2][y2]=='J')+(mat[x3][y3]=='J')+(mat[x4][y4]=='J')>=)
ans=max(ans,dx*dx+dy*dy);
}
}
cout<<ans<<endl;
return ;
}
洛谷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 ...
随机推荐
- angularJs-HelloWorld
AngularJS使用了不同的方法,它尝试去补足HTML本身在构建应用方面的缺陷.AngularJS通过使用我们称为标识符(directives)的结构,让浏览器能够识别新的语法. 1使用双大括号{{ ...
- [2018-10-17]宁波dotnet社区(NBDNC)第一次问卷关于dotnet技术栈的小调查
最近(2018年10月7日至10月17日),为配合确定下一次社区线下活动主题,做了一次宁波dotnet社区(NBDNC)的本地dotnet技术栈调研,设计了一份问卷,在此做一次记录. 导出的问卷统计结 ...
- PAT 天梯赛 L2-022. 重排链表 【数据结构】
题目链接 https://www.patest.cn/contests/gplt/L2-022 思路 先用结构体 把每个结点信息保存下来 然后深搜一下 遍历一下整个链表 然后就重新排一下 但是要注意一 ...
- 【Leetcode-easy】Longest Common Prefix
思路:每次从字符数组中读取两个字符串比较.需要注意输入字符串为空,等细节. public String longestCommonPrefix(String[] strs) { if(strs==nu ...
- iOS实时监控网络状态的改变
在网络应用中,有的时候需要对用户设备的网络状态进行实时监控,有两个目的: (1)让用户了解自己的网络状态,防止一些误会(比如怪应用无能) (2)根据用户的网络状态进行智能处理,节省用户流量,提高用户体 ...
- POJ 2409 Let it Bead:置换群 Polya定理
题目链接:http://poj.org/problem?id=2409 题意: 有一串n个珠子穿起来的项链,你有k种颜色来给每一个珠子染色. 问你染色后有多少种不同的项链. 注:“不同”的概念是指无论 ...
- 分享知识-快乐自己:Hibernate 中的 HQL 语句的实际应用
概要: Hibernate 支持三种查询方式: HQL查询.Criteria查询及原声 SQL (Native SQL)查询. HQL(Hibernate Query Language,Hiberna ...
- Elasticsearch: Five Things I was Doing Wrong
Elasticsearch: Five Things I was Doing Wrong Update: Also check out my series on scaling Elasticsear ...
- VC++动态链接库(DLL)编程深入浅出(转帖:基础班)
1.概论 先来阐述一下DLL(Dynamic Linkable Library)的概念,你可以简单的把DLL看成一种仓库,它提供给你一些可以直接拿来用的变量.函数或类.在仓库的发展史上经历了“无库-静 ...
- mongdb启动问题
问题:Detected unclean shutdown - /data/db/mongod.lock is not empty. old lock file:/data/db/mongod.lock ...