CodeForces-1301D Time to Run


传送门:CodeForces-1301D

思路分析

构造一种走法,可以走完所有的边:

  1. 向右走m-1步到达右上角
  2. 向下走n-1步再向上走n-1步回到原处
  3. 向左走一步
  4. 重复2,3直到回到左上角
  5. 向下走一步
  6. 向右走m-1步,再向左走m-1步回到原处
  7. 重复5,6
  8. 最后向上走n-1步回到原点

样例输入

3 3 4

样例输出

YES
2
2 R
2 L

AC代码


#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <vector>
#include <string>
#include <cstdio>
#include <chrono>
#include <random>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ls x<<1
#define rs x<<1|1
#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define fun function
#define lowbit(x) x&(-x)
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 0x3f3f3f3f;

vector<pair<int,char> >ans;
int n,m,k;

void go(int s,char x) {
    if(!s)return ;
    if(k<=s) {
        ans.push_back(mp(k,x));
        cout<<"YES\n"<<ans.size()<<endl;
        for(auto i:ans)
            cout<<i.fi<<" "<<i.se<<endl;
        exit(0);
    }
    k-=s;
    ans.push_back(mp(s,x));

}

int main() {
    IOS;
#ifdef xiaofan
    freopen("1.in","r",stdin);
    freopen("1.out","w",stdout);
#endif

    cin>>n>>m>>k;
    go(m-1,'R');
    for(int i=1; i<=m-1; i++) {
        go(n-1,'D');
        go(n-1,'U');
        go(1,'L');
    }
    for(int i=1; i<=n-1; i++) {
        go(1,'D');
        go(m-1,'R');
        go(m-1,'L');
    }
    go(n-1,'U');
    cout<<"NO"<<endl;





    return 0;
}

文章作者: 小凡
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 小凡 !
评论
  目录
隐藏
{% if theme.sakura.enable %}{% endif %}