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 ...
随机推荐
- HDU6030 Happy Necklace(递推+矩阵快速幂)
传送门:点我 Little Q wants to buy a necklace for his girlfriend. Necklaces are single strings composed of ...
- Python+Selenium学习--自动生成HTML测试报告
前言 在脚本运行完成之后,除了在log.txt 文件看到运行日志外,我们更希望能生一张漂亮的测试报告来展示用例执行的结果. HTMLTestRunner 是Python 标准库的unit ...
- 648. Replace Words 替换成为原来的单词
[抄题]: In English, we have a concept called root, which can be followed by some other words to form a ...
- Linux终端命令
一.文件目录类 1.建立目录:mkdir 目录名2.删除空目录:rmdir 目录名3.无条件删除子目录: rm -rf 目录名4.改变当前目录:cd 目录名 (进入用户home目录:cd ~;进入上一 ...
- android 自定义 Application
android系统会为每个程序运行时创建一个Application类的对象且仅创建一个,所以Application可以说是单例 (singleton)模式的一个类.且application对象的生命周 ...
- rabbitmq shovel插件
官网说明https://www.rabbitmq.com/shovel.html#management-status 启用shovel插件命令: rabbitmq-plugins enable rab ...
- 深入理解JVM(一)编译openJDK
此文总结的很不错:https://www.cnblogs.com/ACFLOOD/p/5528035.html 准备openJDK源码和环境 1.在linux和macOS上编译openJDK更加友好, ...
- Installing TensorFlow on Ubuntu or Windows
Installing TensorFlow on Ubuntu 显卡驱动:http://developer2.download.nvidia.com/compute/cuda/8.0/secure/P ...
- 《Linux就该这么学》第二天课程
秦时明月经典语录:很多人被命运安排,而我安排命运.——卫庄 今天介绍了VM 虚拟机的安装以及Linux系统的安装,还讲解了Linux内核 RPM:降低软件的安装难度 源代码+安装规则→将程序源代码与安 ...
- Linux 第十三天
十五.shell编程 1.Shell是什么 1)Shell是一个命令行解释器,它为用户提供了一个向Linux内核发送请求以便运行程序的界面系统级程序,用户可以用Shell来启动.挂起.停止甚至是编写一 ...