ZOJ 2975 Thinking

Source: Internet
Author: User

Test instructions gives a rectangle asking how many sub-rectangles there are in the four corners of the letters are the same

At first, the violence wrote a first-in-one. Number and then enumerate the number of two columns and then hold the number down to determine whether there is no unexpected timeout.

And then I thought about it. When we have determined the number of two columns to look down when we find the tot edge and the first edge of the same letter these edges can be composed (tot-1) *tot a rectangle to satisfy the test instructions

In order to avoid repeated searches need a map to record the length of the rectangle because of the longest 100 we have retrieved the letter *1000*1000+ left column number *1000+ right column number

#include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> #include <    String> #include <map>using namespace Std;int n,m;char a[300][300];int main () {int t;    scanf ("%d", &t);        while (t--) {map<int, int >q;        Q.clear ();        int sum=0;        scanf ("%d%d", &n,&m);        for (int i=1;i<=n;i++) scanf ("%s", a[i]+1); for (int i=1;i<=n-1;i++) {for (int. k=1;k<=m-1;k++) {for (int j=k+1;j<=                    m;j++) {if (a[i][k]!=a[i][j]) continue;                    int x=a[i][k]-' a ';                    if (q[x*1000000+k*1000+j]!=0) continue;                    int tot=1;                        for (int l=i+1;l<=n;l++) {if (A[l][j]==a[l][k]&&a[l][j]==a[i][j])                            {tot++; Q[x*1000000+k*1000+j]=1;                }} sum+= (tot-1) *TOT/2;    }}} printf ("%d\n", sum); }}

  

ZOJ 2975 Thinking

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.