HDU 6020---MG loves apple(枚举)
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)

思路:

代码如下:
#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(枚举)的更多相关文章
- hdu 6020 MG loves apple 恶心模拟
题目链接:点击传送 MG loves apple Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Ja ...
- 【HDU 6020】 MG loves apple (乱搞?)
MG loves apple Accepts: 20 Submissions: 693 Time Limit: 3000/1500 MS (Java/Others) Memory Limit: ...
- hdu 6021 MG loves string (一道容斥原理神题)(转)
MG loves string Accepts: 30 Submissions: 67 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- hdu 6021 MG loves string
MG loves string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others ...
- 【BestCoder Round #93 1002】MG loves apple
[题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=6020 [题意] 给你一个长度为n的数字,然后让你删掉k个数字,问你有没有删数方案使得剩下的N-K个 ...
- ●HDU 6021 MG loves string
题链: http://acm.hdu.edu.cn/showproblem.php?pid=6021 题解: 题意:对于一个长度为 N的由小写英文字母构成的随机字符串,当它进行一次变换,所有字符 i ...
- 【HDU 6021】 MG loves string (枚举+容斥原理)
MG loves string Accepts: 30 Submissions: 67 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- MG loves string
MG loves string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others ...
- HDU 4876 ZCC loves cards(暴力剪枝)
HDU 4876 ZCC loves cards 题目链接 题意:给定一些卡片,每一个卡片上有数字,如今选k个卡片,绕成一个环,每次能够再这个环上连续选1 - k张卡片,得到他们的异或和的数,给定一个 ...
- hdu 4873 ZCC Loves Intersection(大数+概率)
pid=4873" target="_blank" style="">题目链接:hdu 4873 ZCC Loves Intersection ...
随机推荐
- java引用
java1.2之后将引用分为强引用(Strong Reference).软引用(Soft Reference).弱引用(Weak Reference).虚引用(Phantom Reference)4种 ...
- 2018 宁夏省赛 F. Moving On
题目链接 https://nanti.jisuanke.com/t/28406 大意是 有n(<=200)个城市,城市间有路(Input给了邻接矩阵) 每个城市有一个危险值,然后是q(2e4) ...
- python import hashllb
http://www.cnblogs.com/alex3714/articles/5161349.html 用于加密相关的操作,3.x里代替了md5模块和sha模块,主要提供 SHA1, SHA224 ...
- 微信小程序记账本进度一
一,1.注册微信公众号 2.点击“立即注册”后,点击“”小程序“” 3.填写邮箱等信息.完成并激活.
- 545. Boundary of Binary Tree二叉树的边界
[抄题]: Given a binary tree, return the values of its boundary in anti-clockwise direction starting fr ...
- 150. Evaluate Reverse Polish Notation逆波兰表达式
[抄题]: Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are ...
- IOS Javascript Date的坑
Date对象是JavaScript提供的日期和时间的操作接口,它有多种用法.手册上或者网上也有很多文章介绍,这里就不再次复述了. 上次遇到一个坑,这里总结下,也不是什么大问题,若是如果有经验,就不会花 ...
- PAT 甲级 1002 A+B for Polynomials (25 分)
1002 A+B for Polynomials (25 分) This time, you are supposed to find A+B where A and B are two polyno ...
- C++ 提取网页内容系列之三
标 题: C++ 提取网页内容系列作 者: itdef链 接: http://www.cnblogs.com/itdef/p/4171659.html 欢迎转帖 请保持文本完整并注明出处 这次继续下载 ...
- c++ stl源码剖析学习笔记(一)uninitialized_copy()函数
template <class InputIterator, class ForwardIterator>inline ForwardIterator uninitialized_copy ...