[ACM] POJ2965 ver.2

if(a[i][j]==’+’)直接把结果矩阵里面以i,j为中心的十字全部改变bool值就好了,方便的算法
但是应该效率高啊 怎么这么慢.. 比递归慢好几倍 奇怪..

#include <cstdio>
#include <cstring>
int main() {
    char a[4][5];
    int r[32];
    int i,j,k,n=0,temp;
    for(i=0;i<4;i++)
        gets(a[i]);
    for(i=0;i<4;i++)
        for(j=0;j<4;j++) {
            temp=0;
            for(k=0;k<4;k++)
                temp+=a[i][k]/2+a[k][j]/2;
            temp-=a[i][j]/2;
            if(temp%2) {
                r[n++]=i;
                r[n++]=j;
            }
        }
    printf("%d\n",n/2);
    for(i=0;i<n;i+=2)
        printf("%d %d\n",r[i]+1,r[i+1]+1);
}

Leave a Reply

Your email address will not be published. Required fields are marked *