QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#419396 | #6429. Let's Play Curling | yulishen | WA | 1ms | 3620kb | C++14 | 1.8kb | 2024-05-23 21:28:22 | 2024-05-23 21:28:22 |
Judging History
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: 1ms
memory: 3620kb
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: ''