当前位置: 代码迷 >> 综合 >> 733C. Epidemic in Monstropolis codeforces(模拟)
  详细解决方案

733C. Epidemic in Monstropolis codeforces(模拟)

热度:79   发布时间:2024-01-10 18:47:46.0

写的不怎么好,有好多漏洞,到最后是看测试数据一点一点改才过的,不过也算得到锻炼了。

 #include<bits/stdc++.h>
#define MAX 0x3f3f3f3f
using namespace std;
long long a[505],b[505];
struct node
{int l;int r;
}arr[505];
struct road
{int v;char d;
}arr1[505];
int visit[505];
int main()
{int n,m,flag=0;cin>>n;for(int i=1;i<=n;i++)cin>>a[i];cin>>m;for(int i=1;i<=m;i++)cin>>b[i];int k=0,l=1,sum;for(int i=1;i<=m;i++){sum=0;if(l>n){flag=1;break;}arr[++k].l=l;int x;if(i==m){x=l;}if(!flag)for(int j=l;j<=n;){sum+=a[j];if(sum==b[m]&&j<n&&j>=x){flag=1;break;}else if(sum==b[i]){arr[k].r=j;l=++j;break;}else if(sum>b[i]){flag=1;break;}else if(sum<b[m]&&j==n){flag=1;break;}elsej++;}elsebreak;}if(flag)cout<<"NO"<<endl;else{sum=k;long long max1,sum1,min1;k=0;int now=0,num;for(int i=1;i<=sum;i++){max1=0;min1=MAX;for(int j=arr[i].l;j<=arr[i].r;j++){if(max1<a[j]){max1=a[j];num=j;}if(min1>a[j])min1=a[j];}if(min1==max1){if(max1!=b[i])flag=1;continue;}a[num]=0;int spot;spot=num-now;while(max1!=b[i]){for(int j=num-1;j>=arr[i].l;j--){if(!a[j])continue;else if(a[j]<max1){arr1[++k].v=spot;arr1[k].d='L';max1+=a[j];spot--;a[j]=0;now++;num=j;}else if(a[j]==max1){spot--;continue;}elsebreak;}for(int j=num+1;j<=arr[i].r;j++){if(!a[j])continue;else if(a[j]<max1){arr1[++k].v=spot;arr1[k].d='R';max1+=a[j];a[j]=0;now++;num=j;}else if(a[j]==max1){spot++;continue;}elsebreak;}}}if(!flag){cout<<"YES"<<endl;for(int i=1;i<=k;i++)cout<<arr1[i].v<<' '<<arr1[i].d<<endl;}elsecout<<"NO"<<endl;}return 0;
}