题目链接:点击传送
MG loves apple
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
A valid number does not contain a leading zero, and these apples have just made a valid N digit number.
MG has the right to take away K apples in the sequence, he wonders if there exists a solution: After exactly taking away K apples, the valid N−K digit number of remaining apples mod 3 is zero.
MG thought it very easy and he had himself disdained to take the job. As a bystander, could you please help settle the problem and calculate the answer?
And as for each case, there are 2 integer N(1<=N<=100000),K(0<=K<N) in the first line which indicate apple-number, and the number of apple you should take away.
MG also promises the sum of N will not exceed 1000000。
Then there are N integers X in the next line, the i-th integer means the i-th gold’s value(0<=X<=9).
If the solution exists, print”yes”,else print “no”.(Excluding quotation marks)
5 2
11230
4 2
1000
no
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e5+,M=1e6+,inf=;
const ll INF=1e18+,mod=;
int num[N][];
int check0(int a,int x,int y,int z)
{
if(a<||x<||y<||z<)return ;
int ans=;
if(x>=&&y>=&&z>=)
{
int xx=x,yy=y,zz=z;
xx-=;yy-=;zz-=;
int l=(xx/+yy/);
zz-=min(zz/,l)*;
if(zz<=a)ans=;
}
if(x>=&&y>=&&z>=)
{
int xx=x,yy=y,zz=z;
xx-=;yy-=;zz-=;
int l=(xx/+yy/);
zz-=min(zz/,l)*;
if(zz<=a)ans=;
}
int xx=x,yy=y,zz=z;
int l=(xx/+yy/);
zz-=min(zz/,l)*;
if(zz<=a)ans=;
return ans;
}
int check1(int a,int x,int y,int z)
{
return max(check0(a,x-,y,z-),check0(a,x,y-,z-));
}
int check2(int a,int x,int y,int z)
{
return max(check0(a,x,y-,z-),check0(a,x-,y,z-));
}
char a[N];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
memset(num,,sizeof(num));
int n,K;
scanf("%d%d",&n,&K);
scanf("%s",a+);
if(K==n-)
{
int mmp=;
for(int i=;i<=n;i++)
if(a[i]%==)mmp=;
if(mmp)printf("yes\n");
else printf("no\n");
continue;
}
int sum=;
for(int i=;i<=n;i++)
sum+=a[i]-'';
int x=sum%;
for(int i=n;i>=;i--)
{
int x=(a[i]-'')%;
num[i][]=num[i+][];
num[i][]=num[i+][];
num[i][]=num[i+][];
num[i][x]++;
}
int ans=;
/// 枚举以i+1为起点的,去掉前i个,后面的需要去掉k-i个,进行check()
for(int i=;i<=K;i++)
{
if(a[i+]=='')continue;
if(x==)ans=max(ans,check1(num[i+][],num[i+][],num[i+][],K-i));
else if(x==)ans=max(ans,check2(num[i+][],num[i+][],num[i+][],K-i));
else ans=max(ans,check0(num[i+][],num[i+][],num[i+][],K-i));
x-=a[i+]-'';
x=(x%+)%;
}
if(ans)
printf("yes\n");
else
printf("no\n");
}
return ;
}