Codeforces Round #619 (Div. 2)D(模拟)

先把一种最长路线记录下来,根据k的大小存到ans中相应的答案再输出

 1 #define HAVE_STRUCT_TIMESPEC
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 vector<char>vv;
 5 vector<pair<int,char>>ans;
 6 int main(){
 7     ios::sync_with_stdio(false);
 8     cin.tie(NULL);
 9     cout.tie(NULL);
10     int n,m,k;
11     cin>>n>>m>>k;
12     int mx=4*m*n-2*m-2*n;
13     if(k>mx){
14         cout<<"NO\n";
15         return 0;
16     }
17     for(int i=1;i<n;++i)
18         vv.emplace_back('D');
19     for(int i=1;i<m;++i)
20         vv.emplace_back('R');
21     for(int j=m;j>1;--j){
22         for(int i=n;i>1;--i)
23             vv.emplace_back('U');
24         for(int i=1;i<n;++i)
25             vv.emplace_back('D');
26         vv.emplace_back('L');
27     }
28     for(int i=n-1;i>=1;--i){
29         vv.emplace_back('U');
30         for(int j=1;j<m;++j)
31             vv.emplace_back('R');
32         for(int j=m;j>1;--j)
33             vv.emplace_back('L');
34     }
35     char pos=vv[0];
36     int cnt=1;
37     for(int i=1;i<k;++i)
38         if(pos==vv[i])
39             ++cnt;
40         else{
41             ans.push_back({cnt,pos});
42             pos=vv[i];
43             cnt=1;
44         }
45     if(cnt)
46         ans.push_back({cnt,pos});
47     cout<<"YES\n";
48     cout<<ans.size()<<"\n";
49     for(auto it:ans)
50         cout<<it.first<<" "<<it.second<<"\n";
51     return 0;
52 }

猜你喜欢

转载自www.cnblogs.com/ldudxy/p/12313041.html
今日推荐