题目链接:点击传送

MG loves apple

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)

Problem Description
MG is a rich boy. He has n apples, each has a value of V(0<=V<=9).

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?

 
Input
The first line is an integer T which indicates the case number.(1<=T<=60)

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).

 
Output
As for each case, you need to output a single line.

If the solution exists, print”yes”,else print “no”.(Excluding quotation marks)

 
Sample Input
2
5 2
11230
4 2
1000
 
Sample Output
yes
no
 
Source
思路:枚举以i+1为起点的,去掉前i个,后面的需要去掉k-i个,进行check()
#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 ;
}
 

hdu 6020 MG loves apple 恶心模拟的更多相关文章

  1. 【HDU 6020】 MG loves apple (乱搞?)

    MG loves apple  Accepts: 20  Submissions: 693  Time Limit: 3000/1500 MS (Java/Others)  Memory Limit: ...

  2. hdu 6021 MG loves string

    MG loves string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others ...

  3. hdu 6021 MG loves string (一道容斥原理神题)(转)

    MG loves string    Accepts: 30    Submissions: 67  Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  4. HDU 5805 NanoApe Loves Sequence (模拟)

    NanoApe Loves Sequence 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5805 Description NanoApe, the ...

  5. HDU 5806 NanoApe Loves Sequence Ⅱ (模拟)

    NanoApe Loves Sequence Ⅱ 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5806 Description NanoApe, t ...

  6. 【BestCoder Round #93 1002】MG loves apple

    [题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=6020 [题意] 给你一个长度为n的数字,然后让你删掉k个数字,问你有没有删数方案使得剩下的N-K个 ...

  7. HDU 5268 ZYB loves Score (简单模拟,水)

    题意:计算Bestcoder四题的得分. 思路:直接模拟,4项分数直接计算后输出.注意不要低于百分之40的分. //#include <bits/stdc++.h> #include &l ...

  8. ●HDU 6021 MG loves string

    题链: http://acm.hdu.edu.cn/showproblem.php?pid=6021 题解: 题意:对于一个长度为 N的由小写英文字母构成的随机字符串,当它进行一次变换,所有字符 i ...

  9. HDU 5995 Kblack loves flag (模拟)

    题目链接 Problem Description Kblack loves flags, so he has infinite flags in his pocket. One day, Kblack ...

随机推荐

  1. [django]模板template原理

    django 中的render和render_to_response()和locals(): http://www.cnblogs.com/wangchaowei/p/6750512.html 什么是 ...

  2. 让你分分钟了解Web接口测试

    因为前后端架构分离技术的兴起,接口测试也越来越重要,最近一直想总结下,作为一个近三年的测试人员,接口这个词是耳濡目染的,而开发张口闭口也都是这个接口或那个接口怎么怎么样,自己遇到的bug也很多是接口问 ...

  3. UMI标签学习【转载】

    转自: https://club.1688.com/threadview/50123159.htm 简单介绍一下利用单分子标签(Unique Molecular Identifier,UMI)对残留噪 ...

  4. [LeetCode] 310. Minimum Height Trees_Medium tag: BFS

    For a undirected graph with tree characteristics, we can choose any node as the root. The result gra ...

  5. AdaBoost Classifier和Regressor

    Adaboost原理传送门 AdaBoost在我看理论课程的时候,以分类为例子来讲解的,谁知道sklearn里面基本上都有classifier和regressor两种.这个倒是我没想到的!!! fro ...

  6. mysql的转储SQL文件

    1.转储数据库的SQL文件,有两个选择,一是转储结构:另一种是转储数据与结构: 2.以上两种转储都不会将事件(定时器)转储,所以特别注意这个,否则以为将数据库备份完了,其实漏掉了所有的事件代码,所以需 ...

  7. zw版【转发·台湾nvp系列Delphi例程】HALCON LocalMin2

    zw版[转发·台湾nvp系列Delphi例程]HALCON LocalMin2 procedure TForm1.Button1Click(Sender: TObject);var img : HUn ...

  8. idea 上搭建 Mybatis 逆向工程

    网盘地址:https://pan.baidu.com/s/1VAILpdgQbFk9t89eEv_nWQ 提取码:xdyc

  9. 应用程序无法正常启动0xc000007b怎么解决

    解决方法两种: 1. 网上搜索中最常见的,缺少DirectX 9 ,去下载一个安上就OK了. 2.第二种情况比较操蛋,其实报的错误应该是:mfc100u.dll丢失 .我在两台电脑上装了相同系统后,台 ...

  10. Java内存管理(一):深入Java内存区域

    本文转自:http://www.cnblogs.com/gw811/archive/2012/10/18/2730117.html#undefined 推荐查看原文,原文格式更好一些. 本文引用自:深 ...