传送门:CodeForces-1301D
思路分析
构造一种走法,可以走完所有的边:
- 向右走m-1步到达右上角
- 向下走n-1步再向上走n-1步回到原处
- 向左走一步
- 重复2,3直到回到左上角
- 向下走一步
- 向右走m-1步,再向左走m-1步回到原处
- 重复5,6
- 最后向上走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;
}