C++&Pascal&Python——【USACO 5.3.4】——Big Barn
来源:互联网 发布:淘宝买家怎么修改价格 编辑:程序博客网 时间:2024/05/24 04:22
Farmer John wants to place a big square barn on his square farm. He hates to cut down trees on his farm and wants to find a location for his barn that enables him to build it only on land that is already clear of trees. For our purposes, his land is divided into N x N parcels. The input contains a list of parcels that contain trees. Your job is to determine and report the largest possible square barn that can be placed on his land without having to clear away trees. The barn sides must be parallel to the horizontal or vertical axis.
EXAMPLE
Consider the following grid of Farmer John's land where `.' represents a parcel with no trees and `#' represents a parcel with trees:
1 2 3 4 5 6 7 8 1 . . . . . . . . 2 . # . . . # . . 3 . . . . . . . . 4 . . . . . . . . 5 . . . . . . . . 6 . . # . . . . . 7 . . . . . . . . 8 . . . . . . . .
The largest barn is 5 x 5 and can be placed in either of two locations in the lower right part of the grid.
PROGRAM NAME: bigbrn
INPUT FORMAT
Line 1:Two integers: N (1 <= N <= 1000), the number of parcels on a side, and T (1 <= T <= 10,000) the number of parcels with treesLines 2..T+1:Two integers (1 <= each integer <= N), the row and column of a tree parcelSAMPLE INPUT (file bigbrn.in)
8 32 22 66 3
OUTPUT FORMAT
The output file should consist of exactly one line, the maximum side length of John's barn.
SAMPLE OUTPUT (file bigbrn.out)
5
大谷仓
农夫约翰想在他的农场上放一个大的方形谷仓。他不喜欢在他的农场里砍树,他想找一个空旷地方放他的谷仓,这样他就能在已经很清澈的土地上建造它。为了我们的目的,他的土地被分成了N * N块。输入包含树的列表。你的工作是确定和报告最大可能的方形谷仓,而不需要清除树木。谷仓边必须与水平或垂直轴平行。
例子
考虑下面的农民约翰的土地。' . '代表一个没有树的地方,‘#’代表了一个有树的地方:
1 2 3 4 5 6 7 8 1 . . . . . . . . 2 . # . . . # . . 3 . . . . . . . . 4 . . . . . . . . 5 . . . . . . . . 6 . . # . . . . . 7 . . . . . . . . 8 . . . . . . . .
最大的谷仓是5 x 5,可以放置在栅格的右下部分的两个位置。
项目名称:bigbrn
输入格式
第一行:两个整数:N(1 <= N <= 1000),边长N,和T(1 <= 10,000)
行2 . .T+ 1:两个整数(1 < =每个整数< = N),树的行和列
示例输入(文件bigbrn.in)
8 32 22 66 3
输出格式
输出文件应该包含一行,即John的谷仓的最大长度。
样例输出(文件bigbrn.out)
5
/*ID : mcdonne1LANG : C++TASK : bigbrn*/#pragma GCC optimize("O3")#include <iostream>#include <fstream>using namespace std;int n, t, x, y, ans;int f[1001][1001];int main () {ifstream fin ("bigbrn.in", ios::in);ofstream fout ("bigbrn.out", ios::out);fin>>n>>t;for (int i = 1; i <= t; i++) {fin>>x>>y;f[x][y] = ~0;}for (int i = 1; i <= n; i++)for (int j = 1; j <= n; j++)if(f[i][j] ^ -1)f[i][j] = max (1, min (min (f[i - 1][j - 1] + 1, f[i][j - 1] + 1), min (f[i - 1][j - 1] + 1, f[i - 1][j] + 1)));for (int i = 1; i <= n; i++)for (int j = 1; j <= n; j++)if (f[i][j] > ans) ans = f[i][j];fout<<ans<<endl;return 0;}
{ID : mcdonne1LANG : PASCALTASK : bigbrn}uses math;varn, t, x, y, i, j, ans : integer;f : array [0..1000, 0..1000] of integer;begin assign (input, 'bigbrn.in'); assign (output, 'bigbrn.out'); reset (input); rewrite (output); read (n, t); for i := 1 to t do begin read (x, y); f[x, y] := not 0; end; for i := 1 to n do for j := 1 to n do if f[i, j] <> -1 then f[i, j] := max (1, min (min (f[i - 1, j - 1] + 1, f[i, j - 1] + 1), min (f[i - 1, j - 1] + 1, f[i - 1, j] + 1))); for i := 1 to n do for j := 1 to n do if f[i, j] > ans then ans := f[i, j]; writeln (ans); close (input); close (output);end.
'''ID : mcdonne1LANG : PYTHON2TASK : bigbrn'''fin = open ('bigbrn.in', 'r')fout = open ('bigbrn.out', 'w')f = [[0 for i in range (1001)] for j in range (1001)]r = fin.readline().split()n = int(r[0])t = int(r[1])for i in range (t) :r = fin.readline().split()f[int(r[0])][int(r[1])] = -1for i in range (1, n + 1) :for j in range (1, n + 1) :if f[i][j] != -1 :f[i][j] = max (1, 1 + min (f[i - 1][j - 1], f[i][j - 1], f[i - 1][j]))ans = 0for i in range (1, n + 1) :for j in range (1, n + 1) :if f[i][j] > ans :ans = f[i][j]fout.write (str(ans) + '\n')fin.close()fout.close()
- C++&Pascal&Python——【USACO 5.3.4】——Big Barn
- USACO算法系列——Big Barn
- usaco 5.3.4 Big Barn
- usaco training 5.3.4 Big Barn 题解
- USACO 5.3 Big Barn dp
- 【USACO题库】5.3.4 Big Barn巨大的牛棚
- 【USACO题库】5.3.4 Big Barn巨大的牛棚
- USACO Section 5.3 Big Barn - DP...
- usaco 5.3 Big Barn(简单DP)
- usaco Big Barn
- C++&Pascal&Python——【USACO 3.4.2】——Electric Fence
- C++&Pascal&Python——【USACO 4.2.2】——The Perfect Stall
- Pascal & C++——USACO Section 1.2 题解
- USACO Big Barn 解题报告
- [动态规划]5.3.4 Big Barn
- Section 5.3 Big Barn
- [usaco]5.4.5 Big Barn题解
- USACO 1997 FALL Big Barn 方形牛棚
- AndroidManifest.xml中android:name功能介绍
- startActivityForResult理解笔记
- 虚拟机的安装 管理及虚拟机快照
- RQPro 公募FOF策略实例——晨星基金筛选和风险平价配置
- 题目:编写一个手机类(Mobile),包括手机品牌(brand)、手机型号(type),方法包括显示手机信息,并编写测试类进行对象的创建 public class Mobile { String br
- C++&Pascal&Python——【USACO 5.3.4】——Big Barn
- FortiGate-30D和FortiWiFi-30D
- 当用户点击移动端链接或JavaScript的可点击的元素时,覆盖显示的高亮颜色。
- SecureCRT的安装与破解(过程很详细!!!)
- 5.Windows PE/COFF
- 人生如戏
- java中的OutputStream与InputStream的图形化理解--就是相对于jvm内存而言的!
- ARM处理器工作模式详解
- week_6_ 3Sum