CodeForces 733C Epidemic in Monstropolis

模拟。

连续的一段$a$合成一个$b$。每段中如果数字只有$1$个,那么可以合成。如果数字个数大于等于$2$个,如果都是一样的,那么无法合成,否则要找到一个可以移动的最大值位置开始移动。一开始写了一个模拟,没考虑到严格大于,$WA$在$106$组数据了......

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
void File()
{
    freopen("D:\\in.txt","r",stdin);
    freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
    char c = getchar();
    x = 0;
    while(!isdigit(c)) c = getchar();
    while(isdigit(c))
    {
        x = x * 10 + c - ‘0‘;
        c = getchar();
    }
}

int n,k;
long long a[600],b[600];
vector<int>p,op;

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    cin>>k;
    for(int i=1;i<=k;i++) cin>>b[i];

    long long sum=0;
    int pos=1,pre=0,fail=0;

    for(int i=1;i<=n;i++)
    {
        sum=sum+a[i];
        if(sum<b[pos]) continue;
        else if(sum>b[pos]) {fail=1; break;}
        else
        {
            if(i-pre==1)
            {
                pos++; sum=0; pre=i;
                continue;
            }

            bool d=0;
            for(int j=pre+1;j<i;j++) if(a[j]!=a[j+1]) d=1;
            if(d==0) {fail=1; break;}

            long long mx=0; int idx;
            for(int j=pre+1;j<=i;j++) mx=max(mx,a[j]);

            for(int j=pre+1;j<=i;j++)
            {
                if(a[j]!=mx) continue;
                if(j-1>=pre+1&&a[j-1]!=mx)
                {
                    idx=j;
                    for(int t=1;t<=idx-pre-1;t++) { p.push_back(idx-pre+pos-1-t+1); op.push_back(0); }
                    for(int t=1;t<=i-idx+1-1;t++) { p.push_back(pos); op.push_back(1); }
                    break;
                }

                else if(j+1<=i&&a[j+1]!=mx)
                {
                    idx=j;
                    for(int t=1;t<=i-idx+1-1;t++) { p.push_back(idx-pre+pos-1); op.push_back(1); }
                    for(int t=1;t<=idx-pre-1;t++) { p.push_back(idx-pre+pos-1-t+1); op.push_back(0); }
                    break;
                }

            }

            pos++; sum=0; pre=i;
        }
    }

    if(pos!=k+1) fail=1;

    if(fail==1) printf("NO\n");
    else
    {
        printf("YES\n");
        for(int i=0;i<p.size();i++)
        {
            cout<<p[i]<<" ";
            if(op[i]==0) cout<<"L";
            else cout<<"R";
            cout<<endl;
        }
    }

    return 0;
}
时间: 2024-12-22 06:21:17

CodeForces 733C Epidemic in Monstropolis的相关文章

(模拟+贪心)codeforces - 733C Epidemic in Monstropolis

题意:有一排数字,大的数字向左或者向右吃相邻的比它小的数字,问能不能吃成另一个数列. 分析: 稍微想一下,可以感觉得到,新数列的每个数字都是由一段连续的原数列子数列相互吃成的,并且这些子数列也是从头连续的相连的,进而组成的原数列.比如 a[0] [1] [2] [3] [4] b[0] [1] 如果b[0]==a[0]+a[1]+a[2],那么b[0]就是a[0-2]吃成的. 那么如果YES,必然b[1]==a[3]+a[4],也就是b[1]是由a[3-4]吃成的. 所以只需要先找出满足的子数列

CF 378(2) C D 模拟

CF 378(2)   好坑,有时间再做一遍 CodeForces 733C 题意:n只怪物,每只重ai,一开始有给定序列a[].问最后是否能变到x只特定序列b[],变化只能是相邻的大吃小. 题解:坑死人的题,,但不要怕去写这种题,在草稿纸上写好思路,一定要动手写.  思路:先把a[]根据b[]进行分段,再对每一段进行分析.细节太多,不自己动手写一遍根本体会不到.. #include<bits/stdc++.h> using namespace std; #pragma comment(lin

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b

Codeforces 841D Leha and another game about graph - 差分

Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or  - 1. To pass th

Codeforces Round #286 (Div. 1) A. Mr. Kitayuta, the Treasure Hunter DP

链接: http://codeforces.com/problemset/problem/506/A 题意: 给出30000个岛,有n个宝石分布在上面,第一步到d位置,每次走的距离与上一步的差距不大于1,问走完一路最多捡到多少块宝石. 题解: 容易想到DP,dp[i][j]表示到达 i 处,现在步长为 j 时最多收集到的财富,转移也不难,cnt[i]表示 i 处的财富. dp[i+step-1] = max(dp[i+step-1],dp[i][j]+cnt[i+step+1]) dp[i+st

Codeforces 772A Voltage Keepsake - 二分答案

You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power store

Educational Codeforces Round 21 G. Anthem of Berland(dp+kmp)

题目链接:Educational Codeforces Round 21 G. Anthem of Berland 题意: 给你两个字符串,第一个字符串包含问号,问号可以变成任意字符串. 问你第一个字符串最多包含多少个第二个字符串. 题解: 考虑dp[i][j],表示当前考虑到第一个串的第i位,已经匹配到第二个字符串的第j位. 这样的话复杂度为26*n*m*O(fail). fail可以用kmp进行预处理,将26个字母全部处理出来,这样复杂度就变成了26*n*m. 状态转移看代码(就是一个kmp

Codeforces Round #408 (Div. 2) B

Description Zane the wizard is going to perform a magic show shuffling the cups. There are n cups, numbered from 1 to n, placed along the x-axis on a table that has m holes on it. More precisely, cup i is on the table at the position x?=?i. The probl