POJ 2965 The Pilots Brothers' refrigerator 枚举

颤抖吧凡人~这才是真正的暴力枚举!!!枚举16个点的状态分别判断...真的...这样也能过...
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
//	freopen("in.txt","r",stdin);
	int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v;
	int a1,b1,c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,n1,o1,p1;
	int z[4][4];
	char x;
	for(i=0;i<4;i++)
	{
		for(j=0;j<4;j++)
		{
			cin>>x;
			if(x=='+') z[i][j]=0;//关
			else if(x=='-') z[i][j]=1;//开
		}
	}

	int w[4][4],min=9999999;
	for(a=0;a<=1;a++)
	{
		for(b=0;b<=1;b++)
		{
			for(c=0;c<=1;c++)
			{
				for(d=0;d<=1;d++)
				{
					for(e=0;e<=1;e++)
					{
						for(f=0;f<=1;f++)
						{
							for(g=0;g<=1;g++)
							{
								for(h=0;h<=1;h++)
								{
									for(i=0;i<=1;i++)
									{
										for(j=0;j<=1;j++)
										{
											for(k=0;k<=1;k++)
											{
												for(l=0;l<=1;l++)
												{
													for(m=0;m<=1;m++)
													{
														for(n=0;n<=1;n++)
														{
															for(o=0;o<=1;o++)
															{
																for(p=0;p<=1;p++)
																{
																	memset(w,-1,sizeof(w));
																	for(r=0;r<4;r++)
																	{
																		for(s=0;s<4;s++)
																		{
																			w[r][s]=z[r][s];
																		}
																	}
																	if(a==1) 
																	{
																		w[0][0]=!w[0][0];
																		w[0][1]=!w[0][1];
																		w[0][2]=!w[0][2];
																		w[0][3]=!w[0][3];
																		w[1][0]=!w[1][0];
																		w[2][0]=!w[2][0];
																		w[3][0]=!w[3][0];
																	}
																	if(b==1)
																	{
																		w[0][0]=!w[0][0];
																		w[0][1]=!w[0][1];
																		w[0][2]=!w[0][2];
																		w[0][3]=!w[0][3];
																		w[1][1]=!w[1][1];
																		w[2][1]=!w[2][1];
																		w[3][1]=!w[3][1];
																	}
																	if(c==1)
																	{
																		w[0][0]=!w[0][0];
																		w[0][1]=!w[0][1];
																		w[0][2]=!w[0][2];
																		w[0][3]=!w[0][3];
																		w[1][2]=!w[1][2];
																		w[2][2]=!w[2][2];
																		w[3][2]=!w[3][2];
																	}
																	if(d==1)
																	{
																		w[0][0]=!w[0][0];
																		w[0][1]=!w[0][1];
																		w[0][2]=!w[0][2];
																		w[0][3]=!w[0][3];
																		w[1][3]=!w[1][3];
																		w[2][3]=!w[2][3];
																		w[3][3]=!w[3][3];
																	}
																	if(e==1)
																	{
																		w[1][0]=!w[1][0];
																		w[1][1]=!w[1][1];
																		w[1][2]=!w[1][2];
																		w[1][3]=!w[1][3];
																		w[0][0]=!w[0][0];
																		w[2][0]=!w[2][0];
																		w[3][0]=!w[3][0];
																	}
																	if(f==1)
																	{
																		w[1][0]=!w[1][0];
																		w[1][1]=!w[1][1];
																		w[1][2]=!w[1][2];
																		w[1][3]=!w[1][3];
																		w[0][1]=!w[0][1];
																		w[2][1]=!w[2][1];
																		w[3][1]=!w[3][1];
																	}
																	if(g==1)
																	{
																		w[1][0]=!w[1][0];
																		w[1][1]=!w[1][1];
																		w[1][2]=!w[1][2];
																		w[1][3]=!w[1][3];
																		w[0][2]=!w[0][2];
																		w[2][2]=!w[2][2];
																		w[3][2]=!w[3][2];
																	}
																	if(h==1)
																	{
																		w[1][0]=!w[1][0];
																		w[1][1]=!w[1][1];
																		w[1][2]=!w[1][2];
																		w[1][3]=!w[1][3];
																		w[0][3]=!w[0][3];
																		w[2][3]=!w[2][3];
																		w[3][3]=!w[3][3];
																	}
																	if(i==1)
																	{
																		w[2][0]=!w[2][0];
																		w[2][1]=!w[2][1];
																		w[2][2]=!w[2][2];
																		w[2][3]=!w[2][3];
																		w[0][0]=!w[0][0];
																		w[1][0]=!w[1][0];
																		w[3][0]=!w[3][0];
																	}
																	if(j==1)
																	{
																		w[2][0]=!w[2][0];
																		w[2][1]=!w[2][1];
																		w[2][2]=!w[2][2];
																		w[2][3]=!w[2][3];
																		w[0][1]=!w[0][1];
																		w[1][1]=!w[1][1];
																		w[3][1]=!w[3][1];
																	}
																	if(k==1)
																	{
																		w[2][0]=!w[2][0];
																		w[2][1]=!w[2][1];
																		w[2][2]=!w[2][2];
																		w[2][3]=!w[2][3];
																		w[0][2]=!w[0][2];
																		w[1][2]=!w[1][2];
																		w[3][2]=!w[3][2];
																	}
																	if(l==1)
																	{
																		w[2][0]=!w[2][0];
																		w[2][1]=!w[2][1];
																		w[2][2]=!w[2][2];
																		w[2][3]=!w[2][3];
																		w[0][3]=!w[0][3];
																		w[1][3]=!w[1][3];
																		w[3][3]=!w[3][3];
																	}
																	if(m==1)
																	{
																		w[3][0]=!w[3][0];
																		w[3][1]=!w[3][1];
																		w[3][2]=!w[3][2];
																		w[3][3]=!w[3][3];
																		w[0][0]=!w[0][0];
																		w[1][0]=!w[1][0];
																		w[2][0]=!w[2][0];
																	}
																	if(n==1)
																	{
																		w[3][0]=!w[3][0];
																		w[3][1]=!w[3][1];
																		w[3][2]=!w[3][2];
																		w[3][3]=!w[3][3];
																		w[0][1]=!w[0][1];
																		w[1][1]=!w[1][1];
																		w[2][1]=!w[2][1];
																	}
																	if(o==1)
																	{
																		w[3][0]=!w[3][0];
																		w[3][1]=!w[3][1];
																		w[3][2]=!w[3][2];
																		w[3][3]=!w[3][3];
																		w[0][2]=!w[0][2];
																		w[1][2]=!w[1][2];
																		w[2][2]=!w[2][2];
																	}
																	if(p==1)
																	{
																		w[3][0]=!w[3][0];
																		w[3][1]=!w[3][1];
																		w[3][2]=!w[3][2];
																		w[3][3]=!w[3][3];
																		w[0][3]=!w[0][3];
																		w[1][3]=!w[1][3];
																		w[2][3]=!w[2][3];
																	}
																	int flag=false;
																	for(r=0;r<4;r++)
																	{
																		for(s=0;s<4;s++)
																		{
																			if(w[r][s]==0)
																				flag=true;
																		}
																	}
																	if(flag==false)
																	{
																		int count=0;
																		if(a==1)count++;
																		if(b==1)count++;
																		if(c==1)count++;
																		if(d==1)count++;
																		if(e==1)count++;
																		if(f==1)count++;
																		if(g==1)count++;
																		if(h==1)count++;
																		if(i==1)count++;
																		if(j==1)count++;
																		if(k==1)count++;
																		if(l==1)count++;
																		if(m==1)count++;
																		if(n==1)count++;
																		if(o==1)count++;
																		if(p==1)count++;
																		if(count<min)
																		{
																			min=count;
																			a1=a;
																			b1=b;
																			c1=c;
																			d1=d;
																			e1=e;
																			f1=f;
																			g1=g;
																			h1=h;
																			i1=i;
																			j1=j;
																			k1=k;
																			l1=l;
																			m1=m;
																			n1=n;
																			o1=o;
																			p1=p;
																		}
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	cout<<min<<endl;
	if(a1==1) cout<<"1 1"<<endl;
	if(b1==1) cout<<"1 2"<<endl;
	if(c1==1) cout<<"1 3"<<endl;
	if(d1==1) cout<<"1 4"<<endl;
	if(e1==1) cout<<"2 1"<<endl;
	if(f1==1) cout<<"2 2"<<endl;
	if(g1==1) cout<<"2 3"<<endl;
	if(h1==1) cout<<"2 4"<<endl;
	if(i1==1) cout<<"3 1"<<endl;
	if(j1==1) cout<<"3 2"<<endl;
	if(k1==1) cout<<"3 3"<<endl;
	if(l1==1) cout<<"3 4"<<endl;
	if(m1==1) cout<<"4 1"<<endl;
	if(n1==1) cout<<"4 2"<<endl;
	if(o1==1) cout<<"4 3"<<endl;
	if(p1==1) cout<<"4 4"<<endl;
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值