[USACO3.3.4]Home on the Range
来源:互联网 发布:mac如何双开战网 编辑:程序博客网 时间:2024/06/07 02:06
Farmer John grazes his cows on a large, square field N (2 <= N <= 250) miles on a side (because, for some reason, his cows will only graze on precisely square land segments). Regrettably, the cows have ravaged some of the land (always in 1 mile square increments). FJ needs to map the remaining squares (at least 2x2 on a side) on which his cows can graze (in these larger squares, no 1x1 mile segments are ravaged).
Your task is to count up all the various square grazing areas within the supplied dataset and report the number of square grazing areas (of sizes >= 2x2) remaining. Of course, grazing areas may overlap for purposes of this report.
PROGRAM NAME: range
INPUT FORMAT
Line 1:N, the number of miles on each side of the field.Line 2..N+1:N characters with no spaces. 0 represents "ravaged for that block; 1 represents "ready to eat".SAMPLE INPUT (file range.in)
6101111001111111111001111101101111001
OUTPUT FORMAT
Potentially several lines with the size of the square and the number of such squares that exist. Order them in ascending order from smallest to largest size.
SAMPLE OUTPUT (file range.out)
2 103 44 1
题意:求边长为2~n的正方形在输入的里面有多少个(只包含1)
做法:枚举每个端点,作为右下角,先求出最大的边长,然后倒着推回去。
至于求当前最大的,显然,如果当前为0,就是0,如果当前为1
就是min(f[l-1,R],f[L-1,R-1],f[L,R-1])+1
这个主要是要满足整个大的是正方形。
/*61011110011111111110011111011011110012 103 44 1*/ /*ID:cqz15311LANG:C++PROG:range*/#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;int ans[255],a[255][255],f[255][255];int n;int read(){int a = 0;char c = getchar();while (!((c>='0') && (c<='9'))) c = getchar();while ((c>='0') && (c<='9')){a = a * 10 + c - 48;c = getchar();}return a;}int main(){freopen("range.in","r",stdin);freopen("range.out","w",stdout);n = read();char c;for (int i=1;i<=n;i++){for (int j=1;j<=n;j++){c = getchar();while (!((c>='0') && (c<='1'))) c = getchar();a[i][j] = c - 48;}}memset(ans,0,sizeof(ans));memset(f,0,sizeof(f));for (int i=1;i<=n;i++){for (int j=1;j<=n;j++){if (a[i][j] == 1){f[i][j] = min(f[i-1][j],min(f[i][j-1],f[i-1][j-1]))+1;ans[f[i][j]]++;}//printf("%d ",f[i][j]);}//puts("");}for (int i=n-1;i>=1;i--){ans[i] += ans[i+1];}for (int i=2;i<=n;i++){if (ans[i] > 0){printf("%d %d\n",i,ans[i]);}}fclose(stdin);fclose(stdout);return 0;}
- USACO3.3.4 Home on the Range (range)
- USACO3.3.4 Home on the Range (range)
- [USACO3.3.4]Home on the Range
- [USACO3.3]家的范围 Home on the Range
- Home on the Range
- usaco Home on the Range
- USACO Home on the Range
- USACO Home on the Range
- usaco Home on the Range
- USACO 3.3 Home on the Range (range)
- Section 3.3 Home on the Range
- usaco Home on the Range java ---DP
- usaco 3.3 Home on the Range
- USACO Home on the Range 解题报告
- USACO Section 3.3 Home on the Range
- USACO--3.3Home on the Range+DP
- usaco Chapter 3 section 3.3 Home on the Range
- USACO Section 3.3 Home on the Range - 优化的BFS..
- ACM集训日记-8月1日
- 变量提升
- SnackDown 2017 Online Elimination Round #Prefix Xor -- 主席树
- leetcode 169. Majority Element | 摩尔投票法
- 趣味编程:静夜思(Swift版)
- [USACO3.3.4]Home on the Range
- [kuangbin带你飞]专题二 搜索进阶 E
- linux 下oracle导入dmp文件
- 查询数据表中某字段值是否有多条记录相同的sql语句
- 【C++】 LeetCode 87. Scramble String
- null
- 2017 多校训练第三场 HDU 6066 RXD's date
- HDU
- webpack进阶