hdu 4770 Lights Against Dudely

madan

这个题超简单的。。。。

在你没读错题不傻逼的情况下。

枚举那盏特殊的灯,然后搞一个dfs就行了。。。。0MS

附上一组哥的超级数据,过了这组数据,难道您还能wa?

/*
    author:ray007great
    version:1.0
*/
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
/*  define */

#define sf(a) scanf("%d",&a)
#define sfs(a) scanf("%s",a)
#define sfI(a) scanf("%I64d",&a)
#define pf(a) printf("%d\n",a)
#define pfI(a) printf("%I64d\n",a)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define rep1(i,a,b) for(int i=(a);i<(b);i++)
#define clr(a) memset(a,0,sizeof(a))
#define pfk  printf("fuck\n")

/*  define */
struct node{
    int x,y;
}lamp[20];
int cnt,res,special,n,m,ans;
bool li[250][250];
char mat[250][250];
void dfs(int c,int step){
    int x=lamp[c].x;
    int y=lamp[c].y;
    if(c>cnt){
        int f=1;
        rep(i,1,cnt){
            x=lamp[i].x;y=lamp[i].y;
            if(li[x][y]==0){
                f=0;
                break;
            }
        }
        if(f==1) res=min(res,step);
        return ;
    }
    if(c==special) {dfs(c+1,step); return ;}
    if(mat[x-1][y]=='#'||mat[x][y+1]=='#') {
        dfs(c+1,step);
        return ;
    }
    dfs(c+1,step);
    bool o1=li[x-1][y],o2=li[x][y+1],o3=li[x][y];
    li[x-1][y]=1;li[x][y+1]=1;li[x][y]=1;
    dfs(c+1,step+1);
    li[x-1][y]=o1,li[x][y+1]=o2,li[x][y]=o3;
}
int main(){
    while(scanf("%d%d",&n,&m)){
        if(n+m==0) return 0;
        cnt=0;
        bool f=0;
        clr(mat);
        rep(i,1,n){
            getchar();
            rep(j,1,m){
                scanf("%c",&mat[i][j]);
                if(mat[i][j]=='.'){
                    f=1;
                    lamp[++cnt].x=i;
                    lamp[cnt].y=j;
                }
            }
        }
        ans=999999;
        rep(i,1,cnt){
            special=i;
            int x=lamp[i].x,y=lamp[i].y;
            if(mat[x-1][y]!='#'&&mat[x][y+1]!='#'){
                clr(li);
                li[x-1][y]=li[x][y+1]=li[x][y]=1;
                res=999999+1;
                dfs(1,1);
                ans=min(ans,res);
            }
            if(mat[x][y+1]!='#'&&mat[x+1][y]!='#'){
                clr(li);
                li[x][y+1]=li[x+1][y]=li[x][y]=1;
                res=999999+1;
                dfs(1,1);
                ans=min(ans,res);
            }
            if(mat[x+1][y]!='#'&&mat[x][y-1]!='#'){
                clr(li);
                li[x+1][y]=li[x][y-1]=li[x][y]=1;
                res=999999+1;
                dfs(1,1);
                ans=min(ans,res);
            }
            if(mat[x][y-1]!='#'&&mat[x-1][y]!='#'){
                clr(li);
                li[x][y-1]=li[x-1][y]=li[x][y]=1;
                res=999999+1;
                dfs(1,1);
                ans=min(ans,res);
            }
        }
        if(f==0) puts("0");
        else if(ans==999999) puts("-1");
        else pf(ans);
    }
    return 0;
}
/*
2 4
.##.
####
*/


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值