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

0ms, 1A, 贴一易懂源码

Posted by vjubge4 at 2019-04-07 10:13:47 on Problem 1683
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int N,M;
char Matrix[7][7];
int I[2000],J[2000], K[2000], R[2000];
char S[2000];
int adv;
bool used[7][7];
int loc[7][7];
char own[7][7];
bool dfs(int tar, int ite){
    if (tar == M){
        for (int i = 0; i < adv; ++i) {
            if (S[i] == 'R'){
                if (loc[I[i]][J[i]] != loc[K[i]][R[i]]){
                    return false;
                }
            } else {
                if (loc[I[i]][J[i]] == loc[K[i]][R[i]]){
                    return false;
                }
            }
        }
        return true;
    }
    if (ite == N){
        return dfs(tar + 1, 0);
    }
    for (int j = 0; j < M; ++j) {
        if (!used[ite][j]){
            used[ite][j] = true;
            loc[ite][j] = tar;
            if (dfs(tar, ite + 1)){
                own[tar][ite] = Matrix[ite][j];
                return true;
            }
            loc[ite][j] = -1;
            used[ite][j] = false;
        }
    }
    return false;
}
int main(){
    int Num;
    scanf("%d", &Num);
    for (int num = 0; num < Num; ++num) {
        scanf("%d %d", &N, &M);
        for (int i = 0; i < N; ++i) {
            getchar();
            for (int j = 0; j < M; ++j) {
                scanf("%c", &Matrix[i][j]);
            }
        }
        adv = 0;
        while (scanf("%d %d %c %d %d", I + adv, J + adv, S + adv, K + adv, R + adv)){
            if (I[adv] == 0 && J[adv] == 0 && K[adv] == 0 && R[adv] == 0){
                break;
            }
            I[adv]--; J[adv] --; K[adv] --; R[adv] --;
            adv ++;
        }
        memset(loc, -1, sizeof(loc));
        memset(used, 0, sizeof(used));
        memset(own, 0, sizeof(own));
        dfs(0,0);
        for (int i = 0; i < M; ++i) {
            for (int j = 0; j < N; ++j) {
                printf("%c", own[i][j]);
            }
            printf("\n");
        }
        printf("\n");
    }
}

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