Brush title records --UVa201 Squares

  This question is made more than one hour, and transferred more than an hour, submitted several times, finally ac, visible just the low level of their own codes pit month.

  The main problems are two, one is to engage in anti-H and V, half did not see the problem, another problem is the format of the output, which also led me wa several times.

  Here is the code AC

#include<cstdio>
//#define LOCAL
#include<cstring>
#include<iostream>
using namespace std;

int H[12][12],V[12][12];

void input(int m){
    char ch;
    int a,b;
    for(int i=0;i<m;i++){
        cin>>ch>>a>>b;
        if(ch=='H')V[a-1][b-1]=1;
        if(ch=='V')H[b-1][a-1]=1;
    }
}

bool check(int x,int j,int k){
    for(int a=0;a<x;a++){
        if(!H[j+a][k]||!H[j+a][k+x])return false;
        if(!V[j][k+a]||!V[j+x][k+a])return false;
    }
    return true;    
}

int main () {
#ifdef LOCAL
freopen("input.txt","r",stdin);
#endif
    int m,n,kase=0,cnt=0,none=1,first=1;
    while(scanf("%d%d",&n,&m)==2){
        if(first)first=0;
        else printf("\n**********************************\n\n");
        printf("Problem #%d\n\n",++kase);
        memset(H,0,sizeof(H));
        memset(V,0,sizeof(V));
        input(m);
        //debug
//        cout<<"**debug**"<<endl;
//        for(int i=0;i<12;i++){
//            for(int j=0;j<12;j++){
//                printf("%d ",V[i][j]);
//            }
//            cout<<endl;
//        }
//        cout<<"**debug**"<<endl;
        //debug
        for(int i=1;i<=n-1;i++){        //i代表size 
            cnt=0;
            for(int j=0;j<12 is ; J ++) {       // I searched on V, from the first to the last row, j is the number of rows 
                for ( int K = 0 ; K < 12 is ; K ++) {   // K is the number of columns 
                    IF (Check (I, J, k)) cnt ++ ;
                     // Debug
 //         cout << "Debug ** **" << endl;
 //         cout << endl << cnt;
 //         cout << "Debug ** **" << endl;
                     // Debug 
                }
            }
            if(cnt){
                printf("%d square (s) of size %d\n",cnt,i);
                none=0;
            }
        }
        if(none)printf("No completed squares can be found.\n");
        none =1;
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/hardworkingshow/p/12294087.html