CF 1924b Collecting Packages

题目链接:cf1294b
思路:按x排个序后,先判断是否可以完成,接着就优先往右走,在往上走

code:

#include <bits/stdc++.h>

using namespace std;

const int maxn = 1000 + 5;
vector<pair<int, int> > v;


int main(void) {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        v.clear();
        v.resize(n + 1);
        for (int i = 1; i <= n; i++) {
            cin >> v[i].first >> v[i].second;
        }

        sort(v.begin() + 1, v.end());
        bool flag = true;
        for (int i = 2; i <= n; i++) {
            if (v[i].second < v[i - 1].second) {
                flag = false;
                break;
            }
        }
        if (flag) {
            cout << "YES" << endl;
            int x = 0, y = 0;
            string ans = "";
            for (int i = 1; i <= n; i++) {
                while (x < v[i].first) {
                    ans += "R";
                    x++;
                }
                while (y < v[i].second) {
                    ans += "U";
                    y++;
                }
            }
            cout << ans;
            cout << endl;
        } else {
            cout << "NO" << endl;
        }
    }


    return 0;
}
发布了50 篇原创文章 · 获赞 52 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/qq_43058685/article/details/104073746
今日推荐