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 ...
随机推荐
- 远程连接ORACLE服务
远程服务端操作系统: Windows Server 2003 Enterprise Edition sp2ORACLE 版本: Oracle 9.2.0.1.0 正式版 本地客户端操作系统: Wind ...
- 100-days: eighteen
Title: Why India's election is among the world's most expensive election n.选举,当选,选举权 expensive adj.昂 ...
- 【python深入】装饰器理解及使用
装饰器,其实就是一个函数,它可以让其他函数在不需要做任何代码变动的前提下额外增加功能,装饰器的返回是一个函数对象. 用一个例子来说明一下什么是函数对象: 从这里可以看到,直接在函数后面加bar(),就 ...
- 【mac上安装&配置&使用git】
转自:https://www.jianshu.com/p/7edb6b838a2e 目录 安装git 创建ssh key.配置git 提交本地项目到GitHub 一.安装Git MAC 上安装Git主 ...
- react项目请求数据的fetch的使用
准备三个文件(封装请求函数),然后测试一下,能不能调用数据 第一个文件 request.js import 'whatwg-fetch'; /** * Parses the JSON returne ...
- Robotics Tools
https://sites.google.com/site/sunglok/rv_tool/robot Robotics Tools Contents 1 Robotics Tutorials 2 R ...
- centos7 下安装pycharm
CentOS 7环境下Pycharm安装流程记录: 1.准备安装文件: 方法1: 使用内置火狐浏览器访问下载最新格式为tar.gz的压缩包 网址:https://www.jetbrains.com/p ...
- 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 ...
- 设计模式学习心得<抽象工厂模式 Abstract Factory>
抽象工厂模式(Abstract Factory Pattern)是围绕一个超级工厂创建其他工厂.该超级工厂又称为其他工厂的工厂.这种类型的设计模式属于创建型模式,它提供了一种创建对象的最佳方式. 在抽 ...
- Julia 下载 安装 juno 开发环境搭建
Windows平台 Julia 的官网 (https://julialang.org) 下载链接(https://julialang.org/downloads) 下载完成后,如果想安装在 C 盘,则 ...