4 条题解

  • 0
    @ 2025-6-6 22:00:22
    /*****************************************
    备注:
    ******************************************/
    #include <queue>
    #include <math.h>
    #include <stack>
    #include <stdio.h>
    #include <iostream>
    #include <vector>
    #include <iomanip>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    #define LL long long
    const int N = 1e5 + 10;
    const int INF = 0x3f3f3f3f;
    char a[10][10];
    char b[10][10];
    void chage(int x , int y)
    {
    	if(x-1>= 1)	b[x-1][y] ^= 1;
    	if(x+1<= 5) b[x+1][y] ^= 1;
    	if(y+1<= 5) b[x][y+1] ^= 1;
    	if(y-1>= 1) b[x][y-1] ^= 1;
    	b[x][y] ^= 1;
    }
    int main()
    {
    	int t;
    	cin >> t;
    	while(t--)
    	{
    		for(int i = 1 ; i <= 5 ; i++)
    			scanf("%s",a[i]+1);
    		int ans = 7;
    		for(int k = 0 ; k < 32 ; k++)
    		{
    			memcpy(b,a,sizeof(b));
    			int num = 0;
    			for(int i = 0 ; i < 5 ; i++)
    			{
    				int m = 1 << i;
    				if( m & k )
    				{
    					num++;
    					chage(1 , i+1);
    				}
    			}
    			for(int i = 1 ; i < 5 ; i++)
    			{
    				for(int j = 1; j <= 5 ;j ++)
    				{
    					if(b[i][j] == '0')
    					{
    						num++;
    						chage(i+1,j);
    					}
    				}
    			}
    			int flag = 1;
    			for(int i = 1 ;flag && i <= 5 ;i++)
    			{
    				if(b[5][i] == '0')
    					flag = 0;
    			}
    			if(flag && num < 7)
    				ans = min(ans , num);
    		}
    		if(ans == 7 ) ans = -1;
    		cout << ans << endl;
    	}
    	return 0;
    }
    

    信息

    ID
    8
    时间
    1000ms
    内存
    128MiB
    难度
    2
    标签
    递交数
    278
    已通过
    164
    上传者