#39235: 測資全對但正式測資WA


n12603579table@gmail.com (施智皓)

學校 : 不指定學校
編號 : 145648
來源 : [36.234.171.196]
最後登入時間 :
2024-04-04 21:19:31
c082. 00118 - Mutant Flatworld Expolrers -- UVa118 | From: [36.234.167.137] | 發表日期 : 2024-01-25 12:46

#0: 100% WA (line:3)

您的答案為: 25 0 E
正確答案為: 40 0 E LOST

程式碼:

#include<iostream>
#include<string>
#include<set>
#include<algorithm>
using namespace std;

int main(){
    int rightLimit, upLimit;
    cin>>rightLimit>>upLimit;

    int xIni, yIni, x, y, xTmp, yTmp;
    char direct, directTmp;

    char scentDirect[upLimit+1][rightLimit+1] = {0};
    set<char> upRight,upLeft,downRight,downLeft;

    while(cin>>xIni>>yIni>>direct){
        x = xIni;
        y = yIni;
        string instruct;

        cin>>instruct;

        bool loseORNOT = false;
        int length = instruct.size();
        for(int i=0; i<length; i++){
            xTmp=x;
            yTmp=y;
            directTmp=direct;


            if(instruct[i] == 'F'){


                if( x==rightLimit && y==upLimit){ //upRight
                    set<char>::iterator it = upRight.find(direct);
                    if(it != upRight.end()) continue;
                }else if(x==0 && y==upLimit){ //upLeft
                    set<char>::iterator it = upLeft.find(direct);
                    if(it != upLeft.end()) continue;
                }else if(x==rightLimit && y==0){ //downRight
                    set<char>::iterator it = downRight.find(direct);
                    if(it != downRight.end()) continue;
                }else if(x==0 && y==0){ //downLeft
                    set<char>::iterator it = downLeft.find(direct);
                    if(it != downLeft.end()) continue;
                }else if(scentDirect[y][x] == direct) continue;


                if(direct == 'E'){
                    x++;
                }
                else if(direct == 'W'){
                    x--;
                }
                else if(direct == 'S'){
                    y--;
                }
                else{
                    y++;
                } //'N'
            }else if(instruct[i] == 'R'){
                if(direct == 'E'){
                    direct='S';
                }
                else if(direct == 'W'){
                    direct='N';
                }
                else if(direct == 'S'){
                    direct='W';
                }
                else{
                    direct='E';
                } //'N'
            }else if(instruct[i] == 'L'){
                if(direct == 'E'){
                    direct='N';
                }
                else if(direct == 'W'){
                    direct='S';
                }
                else if(direct == 'S'){
                    direct='E';
                }
                else{
                    direct='W';
                } //'N'
            }

            if((x>rightLimit || x<0) || (y>upLimit || y<0)){
                if(xTmp==rightLimit && yTmp==upLimit){
                    upRight.insert(directTmp);
                    break;
                }
                else if(xTmp==0 && yTmp==upLimit){
                    upLeft.insert(directTmp);
                     break;
                }
                else if(xTmp==rightLimit && yTmp==0){
                    downRight.insert(directTmp);
                    break;
                }
                else if(xTmp==0 && yTmp==0){
                    downLeft.insert(directTmp);
                    break;
                }
                else{
                    loseORNOT=true;
                    scentDirect[yTmp][xTmp] = directTmp;
                    break;
                }
            }

        }

        if(loseORNOT){
            cout<<xTmp<<" "<<yTmp<<" "<<directTmp<<" "<<"LOST"<<endl;
        }
        else{
            cout<<x<<" "<<y<<" "<<direct<<endl;
        }
    }

    return 0;
}

有考慮四個角落的情形了,而且轉向跟前進的執行都有檢查過,就是不清楚哪裡出問題。
 
請求大神幫忙。
 
 
#39383: Re: 測資全對但正式測資WA


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [101.136.203.77]
最後登入時間 :
2024-04-07 15:34:14
c082. 00118 - Mutant Flatworld Expolrers -- UVa118 | From: [101.137.50.181] | 發表日期 : 2024-02-12 16:28

 

1.

    char scentDirect[upLimit+1][rightLimit+1] = {0};

2.
                if(xTmp==rightLimit && yTmp==upLimit){
                    upRight.insert(directTmp);
                    break;
                }
                else if(xTmp==0 && yTmp==upLimit){
                    upLeft.insert(directTmp);
                     break;
                }
                else if(xTmp==rightLimit && yTmp==0){
                    downRight.insert(directTmp);
                    break;
                }
                else if(xTmp==0 && yTmp==0){
                    downLeft.insert(directTmp);
                    break;
                }

 


1. 二維vla不能這樣初始化

2. 在角落掉下去loseORNOT也要設為true吧

3. 其實這題根本不需要判斷角落吧,這樣只會把程式碼變得很複雜而已

 
ZeroJudge Forum