题意解析:题中所说的不同字符数指的是:对于相同下标index,如果字符相同则数量+1,否则+0。
官方题解:
代码:
///#include<bits/stdc++.h>
///#include<unordered_map>
///#include<unordered_set>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<set>
#include<stack>
#include<map>
#include<new>
#include<vector>
#define MT(a,b) memset(a,b,sizeof(a));
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double pai=acos(-1.0);
const double E=2.718281828459;
const long long mod=1e9+7;
const int INF=0x3f3f3f3f;
const int maxn=1.5e5+5;
int dp[maxn];
char s1[maxn];
char s2[maxn];
struct node
{
int val;
int id;
}a[maxn];
bool cmp(node a,node b)
{
return a.val>b.val;
}
int main()
{
int p;
scanf("%d",&p);
scanf("%s%s",s1+1,s2+1);
int len=strlen(s1+1),ans=0;
for(int i=1; i<=len; i++)
{
dp[i]=dp[i-1]+(s1[i]!=s2[i]);
if(dp[i]*100<=p*i)
ans=i;
}
for(int i=1; i<=len; i++)
{
a[i].val=100*dp[i]-p*i;
a[i].id=i;
}
sort(a+1,a+1+len,cmp);
int last=a[1].id,val=a[1].val;
for(int i=2; i<=len; i++)
{
if(a[i].id>last)
ans=max(ans,a[i].id-last);
else
last=a[i].id;
}
printf("%d\n",ans);
return 0;
}
没怎么看懂,网上也没博客,难受。。。。