ZOJ2067 White Rectangles__email

Source: Internet
Author: User
Tags stdin

Greed, number of rectangles.

You can first record the number of rectangles (x,y) to the left, where you can apply a DP method

Then O (n^3) loop, it's not clear, look at the code.


/******************************************************************************* # Author:neo Fung # Email:neosfung @gmail. com # last modified:2012-02-29 20:24 # filename:zoj2067 White Rectangles.cpp # Description: *************** /#ifdef _msc_ver #define DEBUG #define _crt_secure_ No_deprecate #endif #include <fstream> #include <stdio.h> #include <iostream> #include <string.h&
Gt #include <string> #include <limits.h> #include <algorithm> #include <math.h> #include <

numeric> #include <functional> #include <ctype.h> #define MAX, using namespace std;
Char Board[max][max];

int Sum[max][max]; int main (void) {#ifdef DEBUG freopen (".
  /stdin.txt "," R ", stdin); Freopen (".. 
/stdout.txt "," w ", stdout);
  #endif int n;
    while (~SCANF ("%d", &n)) {memset (sum,0,sizeof (sum));
    memset (board, ' # ', sizeof (board));
    GetChar (); for (int i=1;I<=n;++i) gets (board[i]+1);

		int ans=0;
				for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) if (board[i][j]== '. ')
						{if (board[i][j-1]!= '. ')
					Sum[i][j]=1;
				else sum[i][j]=sum[i][j-1]+1;
				for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) {int len=int_max;
					for (int k=i;k<=n && sum[k][j];++k) {len=min (len,sum[k][j]);
				Ans+=len;
  } printf ("%d\n", ans);
return 0;
 }


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.