1. 程式人生 > >codeforces round 418 div2 補題 CF 814 A-E

codeforces round 418 div2 補題 CF 814 A-E

ont cto sizeof exp else har ret set print

A An abandoned sentiment from past

水題

#include<bits/stdc++.h>

using namespace std;

int a[300],b[300],n,k;
bool cmp(int a,int b)
{
 return a>b;
}
int main()
{//freopen("t.txt","r",stdin);
 scanf("%d%d",&n,&k);
 for(int i=0;i<n;i++)	scanf("%d",&a[i]);
 for(int i=0;i<k;i++)	scanf("%d",&b[i]);
 sort(b,b+k,cmp );
 for(int i=0,j=0;i<n&&j<k;i++)
 	{
 	 if(a[i]==0)a[i]=b[j++];
	}
 for(int i=1;i<n;i++)
 	if(a[i]<=a[i-1]){printf("YES\n");return 0;}
 printf("NO\n");
 return 0;
}

B An express train to reveries

水題

#include<bits/stdc++.h>

using namespace std;
const int N=2000;
int a[N],b[N],ans[N],color[N],n,vis[N];

int main()
{//freopen("t.txt","r",stdin);
 scanf("%d",&n);
 for(int i=0;i<n;i++)scanf("%d",&a[i]);
 for(int i=0;i<n;i++)scanf("%d",&b[i]);
 int sum=0;
 vector<int>ad;
 ad.clear();
 for(int i=0;i<n;i++)
 	 if(a[i]==b[i])ans[i]=a[i],sum++,color[a[i]]++;
 	 	else  ad.push_back(i);
 vector<int>numa;
 numa.clear();
 for(int i=1;i<=n;i++)
 	if(color[i]==0)numa.push_back(i);
 if(sum==n-1)
 	{
 	 ans[ad[0]]=numa[(int)(numa.size()-1)];
	}
		else
			{
			 if((a[ad[0]]==numa[0]&&b[ad[1]]==numa[1])||(b[ad[0]]==numa[0]&&a[ad[1]]==numa[1]))
			 	{
				 ans[ad[0]]=numa[0];
			 	ans[ad[1]]=numa[1];
			 	}
			 	else
			 		{
			 		 ans[ad[1]]=numa[0];
			 	ans[ad[0]]=numa[1];
					}
			}
 for(int i=0;i<n-1;i++)
 	printf("%d ",ans[i]);
 printf("%d\n",ans[n-1]);
 return 0;
}

C An impassioned circulation of affection

水題

#include<bits/stdc++.h>

using namespace std;

int dp[26][1510][1510],maxx[26][1510],ti[26][1510],n,q;
char ss[1510];
int main()
{//freopen("t.txt","r",stdin);
 scanf("%d",&n);
 scanf("%s",&ss);
 for(int i=0;i<26;i++)
 	for(int j=0;j<n;j++)
 		{
 		 int k=j;
 		 while(k<n&&ss[k]==char(i+‘a‘))ti[i][j]++,k++;
		}
 for(int i=0;i<26;i++)
 	{
 	 for(int j=0;j<n;j++)
 	 	{
 	 	 for(int k=1;j+k<=n;k++)
 	 	 	{
 	 	 	 if(dp[i][j][k-1]>=n){dp[i][j][k]=n;maxx[i][k]=max(maxx[i][k],dp[i][j][k]);continue;}
 	 	 	 dp[i][j][k]=dp[i][j][k-1]+ti[i][min(n,j+dp[i][j][k-1])]+1+ti[i][min(n,j+dp[i][j][k-1]+ti[i][j+dp[i][j][k-1]]+1)];
			 if(dp[i][j][k]>n)dp[i][j][k]=n;
			 maxx[i][k]=max(maxx[i][k],dp[i][j][k]);
			}
			
		 
		}
	}
 //memset(dp,0,sizeof(dp));
 scanf("%d",&q);
 for(int i=0;i<q;i++)
 	{
 		char c;int jk;
 		getchar();
 		scanf("%d %c",&jk,&c);
 		int num=c-‘a‘;
 		printf("%d\n",min(n,maxx[num][jk]));
	}
 return 0;
}

D An overnight dance in discotheque

E An unavoidable detour for home

倆小時做了三道水題 還被Hack了一道 該拿什麽拯救我的coding? 我這麽菜可怎麽辦??

codeforces round 418 div2 補題 CF 814 A-E