题目链接

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
 
题意:

思路:

代码如下:

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
int a[];
char s[]; void cal(int &a3, int &E1,int &E2,int N)
{
a3=; E1=; E2=;
for(int i=;i<=N;i++)
{
if(a[i]==) break;
if(a[i]==) a3++;
}
for(int i=;i<=N;i++)
{
if(a[i]==) break;
if(a[i]==) E1=;
if(a[i]==) E2=;
}
return ;
} int main()
{
int T;
cin>>T;
while(T--)
{
int N,K;
int s1=,s2=,s3=;
scanf("%d%d",&N,&K);
scanf("%s",s+);
for(int i=;i<=N;i++)
{
a[i]=s[i]-'';
if(a[i]%==) a[i]=,s1++;
else if(a[i]%==) a[i]=,s2++;
else s3++,a[i]=(a[i])?:;
}
int ans=(s1+s2*)%;
int a3,E1,E2,f=;
cal(a3,E1,E2,N);
for(int C=;C<=s2&&C<=K;C++) ///C->2; B->1; A->0;
{
int B=((ans-C*)%+)%;
for(;B<=s1&&C+B<=K;B=B+)
{
int A=K-C-B;
if(A<=s3)
{
if(A>a3) f=;
else if(B<s1&&E1) f=;
else if(C<s2&&E2) f=;
if(f) break;
}
}
if(f) break;
}
if((N==K+)&&s3) f=;
if(f) puts("yes");
else puts("no");
}
return ;
}

HDU 6020---MG loves apple(枚举)的更多相关文章

  1. hdu 6020 MG loves apple 恶心模拟

    题目链接:点击传送 MG loves apple Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Ja ...

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

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

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

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

  4. hdu 6021 MG loves string

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

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

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

  6. ●HDU 6021 MG loves string

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

  7. 【HDU 6021】 MG loves string (枚举+容斥原理)

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

  8. MG loves string

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

  9. HDU 4876 ZCC loves cards(暴力剪枝)

    HDU 4876 ZCC loves cards 题目链接 题意:给定一些卡片,每一个卡片上有数字,如今选k个卡片,绕成一个环,每次能够再这个环上连续选1 - k张卡片,得到他们的异或和的数,给定一个 ...

  10. hdu 4873 ZCC Loves Intersection(大数+概率)

    pid=4873" target="_blank" style="">题目链接:hdu 4873 ZCC Loves Intersection ...

随机推荐

  1. 如何将 jar 包导入Maven 本地仓库

    案例:oracle jar包由于在maven 远程仓库中找不到,需要先将oracle jar 文件下载到本地,然后导入maven本地仓库,就可以通过 pom 进行依赖 例如:下载后的 jar 地址 D ...

  2. 机器学习性能指标(ROC、AUC、召回率)

    混淆矩阵 构造一个高正确率或高召回率的分类器比较容易,但很难保证二者同时成立 ROC 横轴:FPR(假正样本率)=FP/(FP+TN) 即,所有负样本中被分错的比例 纵轴:TPR(真正样本率)=TP/ ...

  3. stark组件开发之添加功能实现

    添加功能,还是使用, form 组件来完成!  并且 完成添加之后,需要保留原搜索条件. def memory_url(self): '''用于反向生成url, 并且携带,get请求的参数,跳转到下一 ...

  4. 杨其菊201771010134《面向对象程序设计(java)》第四周学习总结

    <面向对象程序设计(java)> 第四周学习总结 第一部分:理论知识 1.类与对象 a.类(class)是构造对象的模板或蓝图.由类构造对象的过程称为创建类的实例: java中类声明的格式 ...

  5. 在URL地址中传值

    URL: re_path('edit_teacher-(\d+).html', views.handle_edit_teacher), HTML: <a href='/edit_teacher- ...

  6. 339. Nested List Weight Sum

    https://leetcode.com/problems/nested-list-weight-sum/description/ Given a nested list of integers, r ...

  7. The current state of generics in Delphi( 转载)

    The current state of generics in Delphi   To avoid duplication of generated code, the compiler build ...

  8. 《Linux就该这么学》第八天课程

        当一个人的心中,有着更高的山峰想要去攀登时,他就不会在意脚下的泥沼. 今天发一下干货,常用命令的一些总结,今天的理论知识比较多. 原创地址:https://www.linuxprobe.com ...

  9. ABP框架系列之五:(Unit Of Work-工作单元)

    Introduction Connection and transaction management is one of the most important concepts in an appli ...

  10. Python开发——7.迭代器、生成器和装饰器

    一.迭代器 1.迭代器协议 (1)迭代器协议是指:对象必须提供一个next方法,执行该方法要么返回迭代中的下一项,要么引起一个StopIteration移除异常以中止迭代. (2)可迭代对象:实现了迭 ...