Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

0秒跑过哈哈哈

Posted by DeadWooder at 2018-08-30 19:53:53 on Problem 1753
暴力第一行  剩下的由上一行确定
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 10;
const int inf = 1e9+5500;
char mp[maxn][maxn],T[maxn][maxn];
int ans;
void str_cop(){
    for(int i=0;i<maxn;++i) for(int j=0;j<maxn;++j) T[i][j]=mp[i][j];
}
void click(int x,int y){
    T[x][y]=(T[x][y]=='b'?'w':'b');
    int dx[4]={0,0,1,-1};
    for(int i=0,j=3;i<4;++i,--j){
        int xx = x+dx[i],yy = y+dx[j];
        if(xx<0||xx>3||yy<0||yy>3) continue;
        T[xx][yy]=(T[xx][yy]=='b'?'w':'b');
    }
}
int head(int t){
    int sum=0;
    for(int i=0;i<4;++i){
        if((1<<i)&t){click(0,i);sum++;}
    }
    return sum;
}
int dfs(int t,char te){
    int sum = 0;
    for(int i=0;i<4;++i){
        if(T[t-1][i]==te){click(t,i);sum++;}
    }
    if(t==3){

        int i;
        for(i=0;i<4;++i) if(T[t][i]==te) return inf;
        if(i==4) return sum;
    }
    else sum+=dfs(t+1,te);
    return sum;
}
int main(){
    while(~scanf("%s",mp[0])){
        ans =  inf;
        for(int i=1;i<4;++i) scanf("%s",mp[i]);
        for(int i=0;i<16;++i){
            str_cop();
            int t = head(i),a,b;
            a = dfs(1,'b');
            str_cop();head(i);
            b = dfs(1,'w');
            t += min(a,b);
            ans = min(ans,t);
        }
        if(ans<1000) printf("%d\n",ans);
        else printf("Impossible\n");
    }
    return  0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator