题目链接:点击传送

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. Centos上执行Shell的四种方式

    注意:我这里说的shell脚本是Bash Shell,其他类型的shell脚本不保证有效 1,方式一:进入shell文件所在目录 ./my.sh执行 ./my.sh ./的意思是说在当前的工作目录下执 ...

  2. L1正则化和L2正则化

    L1正则化可以产生稀疏权值矩阵,即产生一个稀疏模型,可以用于特征选择 L2正则化可以防止模型过拟合(overfitting):一定程度上,L1也可以防止过拟合 一.L1正则化 1.L1正则化 需注意, ...

  3. win10下的iis的配置(服务于asp.net)

    win10下的iis的配置和win7下的是类似的. 1.右键开始,打开控制面板,进入卸载程序中,勾上如下图所示的项目,即可装上iis. 这里写图片描述 2.重启后搜索iis,进入iis配置中.点击网站 ...

  4. linux中的各种$号 位置参数变量

    位置参数变量   $n   #/bin/bash echo $0(代表命令本身); echo $1; (代表第几个参数) echo $2;   [root@LocalWeb01 ~]# ./1.sh ...

  5. vs计算代码行数

    1.用vs打开程序 2.编辑——查找——在文件中查找 3.查找内容^b*[^:b#/]+.*$   应用正则表达式,在整个解决方案中,文件类型空 4.查找全部,仔细盯着右下角数字,查找完毕后会自动消失 ...

  6. 134. Gas Station(数学定理依赖题)

    There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...

  7. mysql插入和更新时自动更新为当前时间

    创建表的时候添加 CREATE TABLE `tmp` (   `id` varchar(32) NOT NULL,  `update_time ` timestamp NOT NULL DEFAUL ...

  8. 圆的k次面积并

    搬运别人的 https://vjudge.net/problem/SPOJ-CIRUT //china no.1 #pragma comment(linker, "/STACK:102400 ...

  9. Linux基础命令---显示文本grep

    grep 按照指定的模式,在文件中搜索匹配的行,将结果显示在标准输出.另外还有两个指令egrep相当于grep –E,fgrep相当于grep -F.如果没有给出文件名,那么从标准输入读取. 此命令的 ...

  10. Linux服务器---配置apache支持用户认证

    Apache支持用户认证 为了服务器的安全,通常用户在请求访问某个文件夹的时候,Apache可以要求用户输入有效的用户名和登录密码 1.创建一个测试目录 [root@localhost cgi-bin ...