codeforces 733CEpidemic in Monstropolis

Posted Gealo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了codeforces 733CEpidemic in Monstropolis相关的知识,希望对你有一定的参考价值。

There was an epidemic in Monstropolis and all monsters became sick. To recover, all monsters lined up in queue for an appointment to the only doctor in the city.

Soon, monsters became hungry and began to eat each other. 

One monster can eat other monster if its weight is strictly greater than the weight of the monster being eaten, and they stand in the queue next to each other. Monsters eat each other instantly. There are no monsters which are being eaten at the same moment. After the monster A eats the monster B, the weight of the monster A increases by the weight of the eaten monster B. In result of such eating the length of the queue decreases by one, all monsters after the eaten one step forward so that there is no empty places in the queue again. A monster can eat several monsters one after another. Initially there were n monsters in the queue, the i-th of which had weight ai.

For example, if weights are [1, 2, 2, 2, 1, 2] (in order of queue, monsters are numbered from 1 to 6 from left to right) then some of the options are:

  1. the first monster can‘t eat the second monster because a1 = 1 is not greater than a2 = 2; 
  2. the second monster can‘t eat the third monster because a2 = 2 is not greater than a3 = 2; 
  3. the second monster can‘t eat the fifth monster because they are not neighbors; 
  4. the second monster can eat the first monster, the queue will be transformed to [3, 2, 2, 1, 2]. 

After some time, someone said a good joke and all monsters recovered. At that moment there were k (k ≤ n) monsters in the queue, the j-th of which had weight bj. Both sequences (a and b) contain the weights of the monsters in the order from the first to the last.

You are required to provide one of the possible orders of eating monsters which led to the current queue, or to determine that this could not happen. Assume that the doctor didn‘t make any appointments while monsters were eating each other.

Input

The first line contains single integer n (1 ≤ n ≤ 500) — the number of monsters in the initial queue.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial weights of the monsters.

The third line contains single integer k (1 ≤ k ≤ n) — the number of monsters in the queue after the joke. 

The fourth line contains k integers b1, b2, ..., bk (1 ≤ bj ≤ 5·108) — the weights of the monsters after the joke. 

Monsters are listed in the order from the beginning of the queue to the end.

Output

In case if no actions could lead to the final queue, print "NO" (without quotes) in the only line. 

Otherwise print "YES" (without quotes) in the first line. In the next n - k lines print actions in the chronological order. In each line print x — the index number of the monster in the current queue which eats and, separated by space, the symbol ‘L‘ if the monster which stays the x-th in the queue eats the monster in front of him, or ‘R‘ if the monster which stays the x-th in the queue eats the monster behind him. After each eating the queue is enumerated again. 

When one monster eats another the queue decreases. If there are several answers, print any of them.

 

题意:给你一串长度为n数列,数字大的可以吃掉比他小的数字(要严格大于)然后这两个数合并成一个数,更新队伍。再给你一串长度为k的数列。

让你进行上述操作使原来序列变成现在这串数。如果不能输出“NO”,可以的话输出“YES”然后输出操作过程,比如x位上

的数吃掉左边的则输出x L,右边的则是x R,不吃则不输出。当然结果可能有多个,输出任意一个。

 

这是一道模拟题,主要还是看细节,

1要合成k个首先要将n分成k份而且每份大小要符合,如果分不了cout NO。

2如果分成的k份全是相同的数那么也不行,因为它们更本吃不了对方合并不了。

3最好找到每一份中的最大值,那么最后输出比较方便只要向两边吃就行,但是如果遇到有几个连续相同的最大值时要稍微考虑一下。

4最后输出的时候要考虑合并后的位置。

要注意的就是这些了。

 

#include <iostream>
#include <cstring>
using namespace std;
int a[550] , b[550] , c[550] , d[550];
int main() {
    int n;
    cin >> n;
    for(int i = 1 ; i <= n ; i++) {
        cin >> a[i];
    }
    int k;
    cin >> k;
    for(int i = 1 ; i <= k ; i++) {
        cin >> b[i];
    }
    int count = 0;
    int sum = 0;
    int temp = 1;
    c[0] = 1;
    for(int i = 1 ; i <= n ; i++) {
        sum += a[i];
        if(sum == b[temp]) {
            temp++;
            sum = 0;
            c[++count] = i;
            continue;
        }
        if(sum > b[temp]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    if(temp < k + 1) {
        cout << "NO" << endl;
        return 0;
    }
    int gg = 1;
    int flag = 0;
    for(int i = 1 ; i <= count ; i++) {
        int MAX = a[gg];
        flag = 0;
        for(int j = gg ; j <= c[i] ; j++) {
            if(MAX < a[j]) {
                MAX = a[j];
                d[i] = j;
            }
            if(j < c[i]) {
                if(a[j] != a[j + 1])
                    flag = 1;
            }
            if(j > gg) {
                if(a[j] != a[j - 1])
                    flag = 1;
            }
        }
        if(c[i] - gg == 0) {
            flag = 1;
            d[i] = gg;
        }
        if((d[i] == gg || d[i] == 0 ) && flag == 1) {
            for(int j = gg ; j < c[i] ; j++) {
                if(a[j] == a[j + 1]) {
                    d[i] = j + 1;
                }
                else {
                    d[i] = j;
                    break;
                }
            }
        }
        gg = c[i] + 1;
        if(flag == 0)
            break;
    }
    if(flag == 0) {
        cout << "NO" << endl;
    }
    else {
        cout << "YES" << endl;
        gg = 1;
        int ca = 0;
        for(int i = 1 ; i <= count ; i++) {
            int pos = d[i];
            int gll = d[i];
            gll -= ca;
            if(c[i] == gg) {
            }
            if(pos == gg) {
                for(int j = pos ; j < c[i] ; j++) {
                    cout << gll << ‘ ‘ << ‘R‘ << endl;
                }
            }
            if(pos == c[i]) {
                for(int j = pos ; j > gg ; j--) {
                    cout << gll << ‘ ‘ << ‘L‘ << endl;
                    gll--;
                    ca++;
                }
            }
            if(pos < c[i] && pos > gg) {
                if(a[d[i]] > a[d[i] - 1]) {
                    for(int j = pos ; j > gg ; j--) {
                        cout << gll << ‘ ‘ << ‘L‘ << endl;
                        gll--;
                        ca++;
                    }
                    for(int j = pos ; j < c[i] ; j++) {
                        cout << gll << ‘ ‘ << ‘R‘ << endl;
                    }
                }
                else {
                    for(int j = pos ; j < c[i] ; j++) {
                        cout << gll << ‘ ‘ << ‘R‘ << endl;
                    }
                    for(int j = pos ; j > gg ; j--) {
                        cout << gll << ‘ ‘ << ‘L‘ << endl;
                        gll--;
                        ca++;
                    }
                }
            }
            gg = c[i] + 1;
            ca += c[i] - pos;
        }
    }
    return 0;
}

以上是关于codeforces 733CEpidemic in Monstropolis的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #733 (Div. 1 + Div. 2) D. Secret Santa

Codeforces Round #733 (Div. 1 + Div. 2) C. Pursuit

Codeforces Round #733 (Div. 1 + Div. 2) C. Pursuit

CodeForces 733B Parade

Codeforces_733_D

Codeforces_733_C