zoukankan      html  css  js  c++  java
  • 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
    ";
    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
    ";
    48     cout<<ans.size()<<"
    ";
    49     for(auto it:ans)
    50         cout<<it.first<<" "<<it.second<<"
    ";
    51     return 0;
    52 }
    保持热爱 不懈努力 不试试看怎么知道会失败呢(划掉) 世上无难事 只要肯放弃(划掉)
  • 相关阅读:
    VB.NET中lambda的写法
    C#中DllImport用法和路径问题
    SQL*Loader 和 Data Pump
    批处理-函数定义及应用01
    Office 2010 KMS激活原理和案例分享
    Hyper-V架构与VMware ESXi的差异
    Tomcat免安装配置2
    Tomcat免安装配置
    域名解析过程
    内部类访问的局部变量必须加final
  • 原文地址:https://www.cnblogs.com/ldudxy/p/12313041.html
Copyright © 2011-2022 走看看