Acdream 1705 (violence)

Source: Internet
Author: User

Test instructions: There's a n*m big lawn, '. ' The open space, ' x ' means planting a tree, now to build a rectangular fence for the lawn, the fence must be built in the open space, ask the fence to build the maximum perimeter is how much, that is, the maximum number of space occupied.
Focus: Violence, the need to preprocess the number of open space on the right of each open space to r[i][j] and the number of empty space d[i][j], and then enumerate each open space as the top left corner of the fence vertex, according to R and D two arrays to get up and left two edges possible length, Then enumerate the upper and left lengths if both the bottom and right conditions are met (that is, do not appear ' X ') to update the maximum value.

#include <stdio.h>#include <string.h>#include <algorithm>using namespace STD;Const intN =505;intN, M;CharG[n][n], R[n][n], d[n][n];intMain () { while(scanf("%d%d", &n, &m) = =2) {memset(R,0,sizeof(r));memset(d,0,sizeof(d)); for(inti =0; I < n; i++)scanf('%s ', G[i]); for(inti =0; I < n; i++) for(intj =0; J < M; J + +) {if(G[i][j] = ='. ') { for(intK = j +1; K < M && G[i][k]! =' x '; k++) r[i][j]++; for(intK = i +1; K < n && g[k][j]! =' x ';                k++) d[i][j]++; }            }intres =0; for(inti =0; I < n; i++) for(intj =0; J < M; J + +) {if(G[i][j] = ='. ') { for(intR1 = R[i][j]; R1 >=1; r1--) for(intD1 = D[i][j]; D1 >=1; d1--)if(R[i + d1][j] >= R1 && d[i][j + r1] >= d1) res = max (res,2* (r1 + d1)); }            }if(Res >=4)printf("%d\n", res);Else            printf("impossible\n"); }return 0;}

Acdream 1705 (violence)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.