2020-2021 ACM-ICPC, Asia Nanjing Regional Contest E. Evil Coordinate

题目:

 

思路分析:

只要是对UDLR全排列,实质上就已经尽可能的避免了重复板块。如果这样都有重叠的,也就意味着再怎么打乱也不行!

代码实现:

/*
*@Author:   GuoJinlong
*@Language: C++
*/
//#include <bits/stdc++.h>
/*
 *                                                     __----~~~~~~~~~~~------___
 *                                    .  .   ~~//====......          __--~ ~~
 *                    -.            \_|//     |||\\  ~~~~~~::::... /~
 *                 ___-==_       _-~o~  \/    |||  \\            _/~~-
 *         __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
 *     _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
 *   .~       .~       |   \\ -_    /  /-   /   ||      \   /
 *  /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
 *  |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
 *           '         ~-|      /|    |-~\~~       __--~~
 *                       |-~~-_/ |    |   ~\_   _-~            /\
 *                            /  \     \__   \/~                \__
 *                        _--~ _/ | .-~~____--~-/                  ~~==.
 *                       ((->/~   '.|||' -_|    ~~-/ ,              . _||
 *                                  -_     ~\      ~~---l__i__i__i--~~_/
 *                                  _-~-__   ~)  \--______________--~~
 *                                //.-~~~-~_--~- |-------~~~~~~~~
 *                                       //.-~~~--\
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 *                               神兽保佑            永无BUG
 */




int a[4]={0,1,2,3};
int op[4][2]={{0,1},{0,-1},{-1,0},{1,0}};
int cnt[4]={0};
map<int,char>mp;
int t;
int x,y;
int check(){
    int x1=0;
    int y1=0;
    for(int i=0;i<4;i++){
        for(int j=0;j<cnt[a[i]];j++){
            x1+=op[a[i]][0];
            y1+=op[a[i]][1];
            if(x1==x&&y1==y){
                return 0;
            }
        }
    }
    return 1;
}
int main(){
    cin>>t;
    mp[0]='U';
    mp[1]='D';
    mp[2]='L';
    mp[3]='R';
    while (t--) {
        cin>>x>>y;
        int flag=0;
        string s;
        cin>>s;
        int x1=0,y1=0;
        mms(cnt,0);
        for(int i=0;i<4;i++){
            a[i]=i;
        }
        
        for(int i=0;i<s.size();i++){
            if(s[i]=='U') cnt[0]++,y1++;
            if(s[i]=='D') cnt[1]++,y1--;
            if(s[i]=='L') cnt[2]++,x1--;
            if(s[i]=='R') cnt[3]++,x1++;
        }
        if((x==0&&y==0)||(x1==x&&y1==y)){
            cout<<"Impossible\n";
            continue;
        }
        do{
            if(check()){
                flag=1;
                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(!flag){
            cout<<"Impossible\n";
        }
    }
    return 0;
}


/**
*  ┏┓   ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃       ┃
* ┃   ━   ┃ ++ + + +
*  ████━████+
*  ◥██◤ ◥██◤ +
* ┃   ┻   ┃
* ┃       ┃ + +
* ┗━┓   ┏━┛
*   ┃   ┃ + + + +Code is far away from
*   ┃   ┃ + bug with the animal protecting
*   ┃    ┗━━━┓ 神兽保佑,代码无bug
*   ┃        ┣┓
*    ┃        ┏┛
*     ┗┓┓┏━┳┓┏┛ + + + +
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛+ + + +
*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郭晋龙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值