首页 > 代码库 > CodeForces 733C Epidemic in Monstropolis

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;}

 

CodeForces 733C Epidemic in Monstropolis