QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#419398#6429. Let's Play CurlingyulishenWA 0ms3600kbC++141.8kb2024-05-23 21:29:492024-05-23 21:29:50

Judging History

你现在查看的是最新测评结果

  • [2024-05-23 21:29:50]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3600kb
  • [2024-05-23 21:29:49]
  • 提交

answer

#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<map>
using namespace std;
int mx,my;
int a[4] = {0,1,2,3};//U D L R
int cnt[4] = {0};
int op[4][2] = {{0,1},{0,-1},{-1,0},{1,0}};
bool check(){//模拟走
    int x = 0,y = 0;
    for(int i = 0;i < 4;i++){
        for(int j = 0;j < cnt[a[i]];j++){
            x+=op[a[i]][0];
            y+=op[a[i]][1];
            if(x == mx&&y == my)  return false;
        }
    }
    return true;
}
int main(){
    int t;
    cin >> t;
    map<int,string>mp;
    mp[0] = 'U';   mp[1] = 'D';
    mp[2] = 'L';   mp[3] = 'R';
    while(t--){
        cin >> mx >> my;  
        string s;
        cin >> s;
        int x = 0,y = 0;
        memset(cnt,0,sizeof(cnt));
        a[0] = 0,a[1] = 1,a[2] = 2,a[3] = 3;
        for(int i = 0;i < s.size();i++){//判断终点位置 记录每个方向能走的次数
            if(s[i] == 'U'){
                cnt[0]++;  y++;
            }
            if(s[i] == 'D'){
                cnt[1]++; y--;
            }
            if(s[i] == 'L'){
                cnt[2]++; x--;
            }
            if(s[i] == 'R'){
                cnt[3]++;  x++;
            }
        }
        if((mx == 0&&my == 0)||(x == mx&&y == my)){//不可能到达情况
            cout << "Impossible\n";
            continue;
        }
        bool ok = false;
        do{
            if(check()){
                ok = true;//记录已找到合适的路径
                for(int i = 0;i < 4;i++){
                    for(int j = 0;j< cnt[a[i]];j++)
                        cout<<mp[a[i]];
                } 
                cout<<endl;
                break;
            }
        }while(next_permutation(a,a+4));
        if(!ok){
            cout << "Impossible\n";
        }
    } 
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3600kb

input:

3
2 2
2 3
1 4
6 5
2 5 3 7 1 7
3 4 3 1 10
1 1
7
7

output:





result:

wrong answer 1st lines differ - expected: '2', found: ''