sicily--1819. Matrix

来源:互联网 发布:淘宝精品店 编辑:程序博客网 时间:2024/05/18 03:36

一开始,真的是被这道题打败了,无论如何都 TL;

不知道怎么去用bitset或者是随机算法,后请教了一个大牛师兄,学习了他的代码让我真正的理解了这样的原因

另收集了一些关于 “bitset”的用法:http://blog.csdn.net/chenhq1991/article/details/7758984

#include<cstdio>#include<bitset>using namespace std;bitset<1000> a[1000], b[1000], c[1000];int size;bool correct(){    for(int i = 0; i < size; i ++)    {        for(int j=0;j<size;j++)        {            if((a[i] & b[j]).count() % 2 == 0)//结果中‘1’的个数            {                if(c[i][j] == 1)return false;            }            else             {                if(c[i][j] == 0)return false;            }        }    }    return true;}int main(){    int testcase;    char ch;    scanf("%d",&testcase);    while(testcase --)    {        scanf("%d",&size);        for(int i=0;i<size;i++)        {            a[i].reset();//初始化为0            b[i].reset();            c[i].reset();        }                for(int i = 0; i < size; i ++)        {            getchar();//回车            for(int j = 0; j < size; j ++)            {                ch = getchar();                if(ch == '1')a[i].set(j);            }        }        for(int i = 0; i < size; i ++)        {            getchar();            for(int j = 0; j < size; j ++)            {                ch = getchar();                if(ch == '1') b[j].set(i);//倒置            }        }        for(int i = 0; i < size; i ++)        {            getchar();            for(int j = 0; j < size; j ++)            {                ch = getchar();                if ( ch == '1') c[i].set(j);            }        }        if( correct() ) printf("YES\n");        else printf("NO\n");    }}                                 


原创粉丝点击