POJ 1623 Squadtrees G++ 四叉树 巧妙 没掌握

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
//英语     看博友分析    抄博友程序      四叉树     巧妙      没掌握
struct state{
	int s1,s2,s3,s4;
	bool check(int n1,int n2,int n3,int n4)
	{
		return n1==s1&&n2==s2&&n3==s3&& n4==s4;
	}
}p[10010];//巧妙
int tot; 
int c1,c2;
char s[140][140];
int a[140][140];
int dfs(int x1,int y1,int x2,int y2)
{
	int t=c1;
	c1++,c2++;
	if(x1==x2&& y1==y2) return a[x1][y1];
	int x3=(x1+x2)/2;
	int y3=(y1+y2)/2;
	int a1=dfs(x1,y1,x3,y3);
	int a2=dfs(x3+1,y1,x2,y3);
	int a3=dfs(x1,y3+1,x3,y2);
	int a4=dfs(x3+1,y3+1,x2,y2);
	if(a1==0&& a2==0 && a3==0 && a4==0)
	{
		c1=c1-4;
		c2=c2-4;
		return 0;
	}
	if(a1==1&& a2==1 && a3==1 && a4==1)
	{
		c1=c1-4;
		c2=c2-4;
		return 1;
	}
	for(int i=2;i<tot;i++)
	{
		if(p[i].check(a1,a2,a3,a4))
		{
			c1=t;
			return i;
		}
	}
	p[tot++]=(state){a1,a2,a3,a4};
	return tot-1;
}
int main()
{
	while(1)
	{
		int n,m;
		cin>>n>>m;
		if(n==0 && m==0)
		{
			break;
		}
		memset(a,0,sizeof(a));
		for(int i=0;i<n;i++)
		{
			scanf("%s",s[i]);
			for(int j=0;j<m;j++)
			{
				a[i][j]=s[i][j]-'0';
			}
		}
		int t=max(n,m);
		int k=1;
		while(k<t)
		{
			k=k<<1;//抄博友程序 
		}
		tot=2;
		c1=c2=0;
		dfs(0,0,k-1,k-1);
		cout<<c2<<" "<<c1<<endl; 
	}
	return 0;
} 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值