POJ3251:Big Square 题解
来源:互联网 发布:姚明 小球知乎 编辑:程序博客网 时间:2024/05/29 14:09
转载请注明出处:http://blog.csdn.net/RavenChau/article/details/78023318
【原题】
Description
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 withN ×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).
Input
Lines 2..N+1: Line i+1 describes line i of the field withN 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.
Output
Sample Input
6J*J*********J***J*********B*********
Sample Output
4
Source
#include <cstdio>#include <cstring>int map[110][110];int main() { int n; scanf("%d", &n); memset(map, 0, sizeof(map)); char ano; scanf("%c", &ano); for(int i = 1; i <= n; i ++) { for(int j = 1; j <= n; j ++) { char c; scanf("%c", &c); if(c == 'J') map[i][j] = 1; else if(c == 'B') map[i][j] = -1; } char ano; scanf("%c", &ano); } int area = 0,ans = 0; for(int i = 1; i <= n; i ++) { for(int j = 1; j <= n; j ++) { if(map[i][j] == 1) { for(int x = i; x <= n; x ++) { for(int y = 1; y <= n; y ++) { if(map[x][y] == 1) { area = (x - i) * (x - i) + (y - j) * (y - j); if(area <= ans) continue; if((i+j-y)>0&&(j+x-i)>0&&(x+j-y)>0&&(y+x-i)>0&&(i+j-y)<=n&&(j+x-i)<=n&&(x+j-y)<=n&&(y+x-i)<=n&&(map[i+j-y][j+x-i]+map[x+j-y][y+x-i]>0) || (i-j+y)>0&&(j-x+i)>0&&(x-j+y)>0&&(y-x+i)>0&&(i-j+y)<=n&&(j-x+i)<=n&&(x-j+y)<=n&&(y-x+i)<=n&&(map[i-j+y][j-x+i]+map[x-j+y][y-x+i]>0) ) { ans = area; } } } } } } } printf("%d\n", ans); return 0;}
- POJ3251:Big Square 题解
- poj3251 & usaco 月赛 2006 Big Square 题解
- POJ3251-Big Square (C语言实现)
- 【枚举】Big Square
- poj 3251 Big Square
- POJ2362《Square》题解
- ZOJ 1909Square 题解
- LeetCode 221 Maximal Square 题解
- 1661: [Usaco2006 Nov]Big Square 巨大正方形
- LeetCode 题解(117): Maximal Square
- codevs 3301 Square words 题解报告
- Codeforces 300D Painting Square 题解
- Codeforces #828B: Black Square 题解
- bzoj 1661 [Usaco2006 Nov]Big Square 巨大正方形
- bzoj 1661: [Usaco2006 Nov]Big Square 巨大正方形 (枚举)
- |BZOJ 1661|暴力|[Usaco2006 Nov]Big Square 巨大正方形
- bzoj 1661: [Usaco2006 Nov]Big Square 巨大正方形 解题报告
- bzoj 1661: [Usaco2006 Nov]Big Square 巨大正方形(枚举)
- 第二周 项目三 体验复杂度
- 自定义日历
- this package import
- 计算机组成原理与体系结构---校验码
- Dangling javadoc
- POJ3251:Big Square 题解
- Ajax
- static{}语句的小总结
- 无限轮播图触摸事件,点击轮播图跳转到另一个Activity
- JVM启动分析
- HTML5 canvas画布
- VMware中安装Linux使用NAT模式后xshell无法ping到Linux
- 读Spring源码的一些杂乱思绪(一)
- Jmeter压力测试简单教程(包括服务器状态监控)