程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> POJ 2965 The Pilots Brothers refrigerator 枚舉

POJ 2965 The Pilots Brothers refrigerator 枚舉

編輯:C++入門知識

[cpp]
顫抖吧凡人~這才是真正的暴力枚舉!!!枚舉16個點的狀態分別判斷...真的...這樣也能過... 
[cpp] 
#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; 

作者:ffq5050139

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved