POJ2956

4 篇文章 0 订阅
#include <iostream>
#include <stdio.h>
#include <string.h>




using namespace std;


struct point
{
    int r,c;
}now;


point st[20];
bool graph[6][6] = {false};
char s;
bool falg = false;
int sum;




bool check()
{
    int i,j;
    for( i = 1; i<5; i++)
     for( j = 1; j<5; j++)
      if(graph[i][j] == false)
       return false;


     return  true;
}




void flip(int x, int y)
{
    int i,j;
    for( i = 1; i < 5; i++)
       graph[x][i] = !graph[x][i];
    for( j = 1; j< 5; j++)
      graph[j][y] = !graph[j][y];
    graph[x][y] = !graph[x][y];
}




void dfs( int x, int y, int step)
{
    if(step == sum)
    {
        falg = check();
        return ;
    }


    if( falg || x == 5)
       return ;


     flip(x,y);






    if(y < 4)
     {
         dfs(x,y+1,step+1);
         now.r = x;
         now.c = y;
         st[step] = now;
     }
    else
     {
         dfs(x+1,1,step+1);
         now.r = x;
         now.c = y;
         st[step] = now;
     }


     flip(x,y);
    if(y < 4)
      dfs(x,y+1,step);
    else
      dfs(x+1,1,step);


}


int main()
{




   sum  = 0;
   falg = false;


   int i,j;
   for( i = 1; i<5; i++)
    for( j = 1; j<5; j++)
    {
        cin>>s;
        if(s == '+')
         graph[i][j] = false;
        else
         graph[i][j] = true;
        // cout<<graph[i][j]<<endl;
    }


   for(sum = 0; sum<=16; sum++)
   {
       dfs(1,1,0);
       if(falg)
        break;
   }
   cout<<sum<<endl;
   for(  i = 0 ; i< sum; i++)
   {
       cout<<st[i].r<<" "<<st[i].c<<endl;


   }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值