E. Mirror Grid Codeforces Round #806 (Div. 4)

Problem - E - Codeforces

题目:

 

题意: 给你一个n*n的表,里面的元素只有1或者0,你可以把其中的0换成1(或者1换0),问你最少经过多少次操作,可以使他旋转4次的表都是一样的。

思路:找关系,每次旋转的关系:这次的x,y和下次的xx,yy的关系:(可以自己找几个点找一下规律)

xx=y

yy=n-x+1

然后走四次,选择需要次数少的换法。

(这里循环外层是包含到了中间那条边(如果是奇数),内层没有,因为这样不会重复计算,可参考样例5).

代码;

/**
*  ┏┓   ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃       ┃
* ┃   ━   ┃ ++ + + +
*  ████━████+
*  ◥██◤ ◥██◤ +
* ┃   ┻   ┃
* ┃       ┃ + +
* ┗━┓   ┏━┛
*   ┃   ┃ + + + +Code is far away from  
*   ┃   ┃ + bug with the animal protecting
*   ┃    ┗━━━┓ 神兽保佑,代码无bug 
*   ┃  	    ┣┓
*    ┃        ┏┛
*     ┗┓┓┏━┳┓┏┛ + + + +
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛+ + + +
*/

#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define sc_int(x) scanf("%d", &x)
#define sc_ll(x) scanf("%lld", &x)
#define pr_ll(x) printf("%lld", x)
#define pr_ll_n(x) printf("%lld\n", x)
#define pr_int_n(x) printf("%d\n", x)
#define ll long long 
using namespace std;

const int N=1000000+100;
int n ,m,h;
ll s[N];
char str[110][110];

int pan(int i ,int j)
{
	int i1=0,i0=0,k=0;
	if(str[i][j]=='1')i1++;
	else i0++;
	//3,4, 4,2   2,1 , 1,3     2,3, 3,3
	for(int ks =1;ks<=3;ks++)
	{
	k=i,i=j,j=n-k+1;
	if(str[i][j]=='1')i1++;
	else i0++;
	}
	return min((4-i0),(4-i1));

}

int main()
{
	int t;
	sc_int(t);
	while(t--)
	{
		sc_int(n);
		for(int i =1;i<=n;i++)
		cin>>str[i]+1;

		int res=0;
		for(int i =1;i<=(n+1)/2;i++)
		{
			for(int j =1;j<=n/2;j++)
			{
				res+=pan(i,j);
			}
		}
		cout<<res<<endl;
	}
	
	return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值