zoukankan      html  css  js  c++  java
  • Codeforces1301D

    其实感觉这道题在D简单了(但我都没做到这一题,路径最多的方式只有一种,将所有的边都走一遍,从第一行开始,向右走到头,然后向左回来,向下一格,向右走到头,然后上下左重复直到第一列,如此重复直到最后一行,最后一步为向上到第一行第一列,注意输出的时候要判断一下0的情况

    #include<bits/stdc++.h>
    using namespace std;
    #define lowbit(x) ((x)&(-x))
    typedef long long LL;
    
    void run_case() {
        int n, m, k;
        cin >> n >> m >> k;
        vector<pair<int,string>> store, ans;
        int cnt = 0;
        for(int i = 1; i <= n; ++i) {
            store.push_back(make_pair(m-1, "R"));
            cnt += store.back().first * store.back().second.size();
            if(i == 1) store.push_back(make_pair(m-1, "L"));
            else store.push_back(make_pair(m-1, "UDL"));
            cnt += store.back().first * store.back().second.size();
            if(i == n) store.push_back(make_pair(n-1, "U"));
            else store.push_back(make_pair(1, "D"));
            cnt += store.back().first * store.back().second.size();
        }
        if(cnt < k) {
            cout << "NO
    ";
            return;
        }
        while(cnt > k) {
            string now = store.back().second;
            int cur = store.back().first*now.size();
            store.pop_back();
            cnt -= cur;
            if(cnt >= k) continue;
            cur = k - cnt;
            if(cur / now.size()) store.push_back(make_pair(cur/now.size(), now));
            now.resize(cur%now.size());
            if(now.size()) store.push_back(make_pair(1, now));
            cnt = k;
        }
        cout << "YES
    ";
        for(auto i : store) {
            if(i.first) ans.push_back(i);
        }
        cout << ans.size() << "
    ";
        for(auto i : ans) {
            cout << i.first << " " << i.second << "
    ";
        }
    }
     
    int main() {
        ios::sync_with_stdio(false), cin.tie(0);
        //cout.setf(ios_base::showpoint);cout.precision(10);
        //int t; cin >> t;
        //while(t--)
        run_case();
        cout.flush();
        return 0;
    }
    View Code
  • 相关阅读:
    Windows10右键添加“在此处打开命令窗口"
    赋值简单理解
    应用 EditPlus 配置 Java 编译环境
    进程和线程的区别
    Java栈与堆
    进程与线程的简单解释
    java的多态性(二)
    内部类详解(很详细)
    java的super和this关键字用法总结
    Java类成员(成员变量和方法)的覆盖与隐藏归纳
  • 原文地址:https://www.cnblogs.com/GRedComeT/p/12306614.html
Copyright © 2011-2022 走看看