题解:P13103 [GCJ 2019 Qualification] You Can Go Your Own Way

· · 题解

题意

给出一个 n\times n 大小的正整数矩阵,要求出:从 1,1 到 n,n 的路线,只有两种可用的移动方式:向东移动一格,以及向南移动一格。你可以进入任何单元格,但不能做出会导致你离开网格的移动。并且不能与给出的路线重和。路线中的每个字符要么是大写 E(表示向东),要么是大写 S(表示向南)

思路

既然不和给出的路线重合,那么我们只需要与给出的路线反过来不就行了?

代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    int cnt=0;
    while(t--)
    {
        cnt++;
        int n;
        cin>>n;
        string s;
        cin>>s;//输入
        int len=s.size();
        cout<<"Case #"<<cnt<<": ";
        for(int i=0;i<len;++i)
        {
            if(s[i]=='E')//反过来
            {
                cout<<'S';
            }
            else
            {
                cout<<'E';
            }
        }
        cout<<endl;
    } 
    return 0;
}