标签:name pre 个数 des lse space bsp 第一个 +=
Description:
给你两个数组,顺序一定,问你第一个数组连续的几个值等于下一个数组连续的几个值,然后寻找这个值得最大值,也就是满足就换
Solution:
用两个变量索引,判断即可
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 1e6 + 1e3;
int a[maxn],b[maxn];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
for(int i = 1;i <= n;++i)
scanf("%d",&a[i]);
for(int i = 1;i <= m;++i)
scanf("%d",&b[i]);
int cnt = 0;
int x = 1,y = 1;
while(x <= n && y <= m)
{
if(a[x] == b[y])
{
++x;++y;++cnt;
}
else if(a[x] < b[y])
{
x++;
a[x] += a[x-1];
}
else if(a[x] > b[y])
{
y++;
b[y] += b[y-1];
}
}
printf("%d\n",cnt);
}
return 0;
}
标签:name pre 个数 des lse space bsp 第一个 +=
原文地址:https://www.cnblogs.com/DF-yimeng/p/9636171.html