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

这道题槽点颇多,但有一点确定,o后面一定不拐弯,+后面一定接上拐弯的|或者-,代码如下

Posted by zhangcy269 at 2023-06-04 00:12:41 on Problem 1048 and last updated at 2023-06-04 00:13:24
//
//  main.cpp
//  1048
//
//  Created by zhangchenyi on 6/1/23.
//

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int bottom,ri;
int invalid(char str[200][200],int row,int col){
    if(str[row][col]=='o') return 1;
    else if(str[row][col]=='+') return 2;
    else if(str[row][col]=='|') return 3;
    else if(str[row][col]=='-') return 4;
    else if(str[row][col]=='?') return 5;
    else if(str[row][col]=='>') return 6;
    else if(str[row][col]==')') return 7;
    else if(str[row][col]==':') return 8;
    else if(str[row][col]=='\\') return 9;
    else if(str[row][col]=='/') return 10;
    else if(str[row][col]<='Z'&&str[row][col]>='A') return 11;
    else return 0;
}
char prec;
void shrink(char str[200][200],char data[200],int &row,int &col,int &dir){
    if(row>=1&&str[row][col]=='|'&&dir!=1){
        while(row>=1&&str[row][col]=='|'&&dir!=1) row--;
        dir=2;
    }
    else if(str[row][col]=='|'&&dir!=2){
        while(str[row][col]=='|'&&dir!=2) row++;
        dir=1;
    }
    else if(col>=1&&str[row][col]=='-'&&dir!=3){
        while(col>=1&&str[row][col]=='-'&&dir!=3) col--;
        dir=4;
    }
    else if(str[row][col]=='-'&&dir!=4){
        while(str[row][col]=='-'&&dir!=4) col++;
        dir=3;
    }
}
int turn(char str[200][200],int row,int col){
    //if(str[row][col]>='A'&&str[row][col]<='Z') return 6;
    //else if(str[row][col]=='o') return 12;
    //else if(str[row][col]==':') return 24;
    //else if(str[row][col]=='?') return 18;
    //else if(str[row][col]=='\\') return 30;
    //else if(str[row][col]=='/') return 36;
    if(str[row][col]=='|') return 2;
    else if(str[row][col]=='-') return 3;
    else return 5;
}
int fun(char str[200][200],char data[200],int row,int col,int dir){
    if(row<0||col<0||!invalid(str,row,col)) return 0;
    shrink(str,data,row,col,dir);
    char c=str[row][col];
    if(c>='A'&&c<='Z'){
        prec='a';
        //cout<<c<<"="<<data[c-'A']-'0'<<endl;
        return data[c-'A']-'0';
    }
    else if(c=='?'){
        prec='?';
        //cout<<"?:"<<endl;
        return fun(str,data,row-1,col,2)||fun(str,data,row+1,col,1)||
        fun(str,data,row,col-1,4)||fun(str,data,row,col+1,3);
    }
    else if(c==')'){
        prec=')';
        //cout<<"):"<<row<<" "<<col<<endl;
        int a=fun(str,data,row+1,col-3,4),b=fun(str,data,row-1,col-3,4);
        //cout<<a<<" && "<<b<<"="<<(a&&b)<<endl;
        return a&&b;
    }
    else if(c=='>'){
        prec='>';
        //cout<<">:"<<row<<" "<<col<<endl;
        int a=fun(str,data,row+1,col-3,4),b=fun(str,data,row-1,col-3,4);
        //cout<<a<<" || "<<b<<"="<<(a||b)<<endl;
        return a||b;
    }
    else if(c=='+'){
        prec='L';
        //cout<<"+:"<<row<<" "<<col<<endl;
        if(dir==4){
            if(turn(str,row+1,col)%2==0) return fun(str,data,row+1,col,1);
            else return fun(str,data,row-1,col,2);
        }
        else if(dir==3){
            if(turn(str,row+1,col)%2==0) return fun(str,data,row+1,col,1);
            else return fun(str,data,row-1,col,2);
        }
        else if(dir==2){
            if(turn(str,row,col+1)%3==0) return fun(str,data,row,col+1,3);
            else return fun(str,data,row,col-1,4);
        }
        else if(dir==1){
            if(turn(str,row,col+1)%3==0) return fun(str,data,row,col+1,3);
            else return fun(str,data,row,col-1,4);
        }
        else while(1);
    }
    else if(c=='o'){
        prec='o';
        //cout<<"o:"<<row<<" "<<col<<endl;
        if(dir==4)
            return !fun(str,data,row,col-1,4);
        else if(dir==3)
            return !fun(str,data,row,col+1,3);
        else if(dir==2)
            return !fun(str,data,row-1,col,2);
        else if(dir==1)
            return !fun(str,data,row+1,col,1);
        else while(1);
    }
    else {
        //cout<<"error:"<<row<<" "<<col<<endl;
        if(prec=='L') while(1);
        return 0;
    }
}
int sol(){
    int cnt=0,f=0,stx=0,sty=0;
    char str[200][200];
    memset(str,0,sizeof(str));
    for(;;cnt++){
        for(int j=0;j<200;j++){
            str[cnt][j]=getchar();
            if(str[cnt][j]==EOF) return EOF;
            if(str[cnt][j]=='?') {stx=cnt;sty=j;}
            if(str[cnt][j]=='\n') break;
            else if(str[cnt][j]=='*') f=1;
        }
        if(f) break;
    }
    //for(int i=0;i<cnt;i++) cout<<str[i];
    //cout<<stx<<" "<<sty<<endl;
    char data[200];
    while(1){
        cin>>data;
        if(!strcmp(data,"*")) break;
        //cout<<data<<endl;
        cout<<fun(str,data,stx,sty,-1)<<endl;
    }
    cin.ignore();
    return 1;
}
int main(int argc, const char * argv[]) {
    while(sol()!=EOF) {cout<<endl;}
    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