hdu 6020 MG loves apple 恶心模拟
题目链接:点击传送
MG loves apple
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
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)
5 2
11230
4 2
1000
no
#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 恶心模拟的更多相关文章
- 【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 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others ...
- hdu 6021 MG loves string (一道容斥原理神题)(转)
MG loves string Accepts: 30 Submissions: 67 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- HDU 5805 NanoApe Loves Sequence (模拟)
NanoApe Loves Sequence 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5805 Description NanoApe, the ...
- HDU 5806 NanoApe Loves Sequence Ⅱ (模拟)
NanoApe Loves Sequence Ⅱ 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5806 Description NanoApe, t ...
- 【BestCoder Round #93 1002】MG loves apple
[题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=6020 [题意] 给你一个长度为n的数字,然后让你删掉k个数字,问你有没有删数方案使得剩下的N-K个 ...
- HDU 5268 ZYB loves Score (简单模拟,水)
题意:计算Bestcoder四题的得分. 思路:直接模拟,4项分数直接计算后输出.注意不要低于百分之40的分. //#include <bits/stdc++.h> #include &l ...
- ●HDU 6021 MG loves string
题链: http://acm.hdu.edu.cn/showproblem.php?pid=6021 题解: 题意:对于一个长度为 N的由小写英文字母构成的随机字符串,当它进行一次变换,所有字符 i ...
- HDU 5995 Kblack loves flag (模拟)
题目链接 Problem Description Kblack loves flags, so he has infinite flags in his pocket. One day, Kblack ...
随机推荐
- 使用SolrJ代码导入,发布搜索服务
搭建solr服务器:http://www.cnblogs.com/liyafei/p/8005571.html 一导入要搜索的字段 1:确定发布搜索的字段,sql语句 SELECT a.id, b. ...
- (转)Elasticsearch查询规则------match和term
es种有两种查询模式,一种是像传递URL参数一样去传递查询语句,被称为简单搜索或查询字符串(query string)搜索,比如 GET /megacorp/employee/_search //查询 ...
- Java读取Excel数据
Java读取Excel数据,解析文本并格式化输出 Java读取Excel数据,解析文本并格式化输出 Java读取Excel数据,解析文本并格式化输出 下图是excel文件的路径和文件名 下图是exce ...
- java的poi技术读取Excel数据
这篇blog主要是讲述java中poi读取excel,而excel的版本包括:2003-2007和2010两个版本, 即excel的后缀名为:xls和xlsx. 读取excel和MySQL相关: ja ...
- Xcode 快捷键及代码格式化
按住apple键点击类名就可以定位到这个类中查看相关定义(在日后的开发中我们会经常这么来做,毕竟要记住iOS开发中所有的API是不现实的,有些API我们可以通过这种方法来查找) PS:下面都是网上百度 ...
- redis的5种数据结构的使用场景介绍
一.redis 数据结构使用场景 原来看过 redisbook 这本书,对 redis 的基本功能都已经熟悉了,从上周开始看 redis 的源码.目前目标是吃透 redis 的数据结构.我们都知道,在 ...
- 浏览器测试string是否为图片
在浏览器中直接打如下代码.其中adcd为图片转成的string data:image/jpeg;base64,abcd
- ActiveMQ 集群负载平衡
目前的架构: 负载均衡方案:========================================= 第二种方案呢,假设我们整个应用是个食堂,这个食堂里面有好多饭口,每个饭口有好多大爷大妈( ...
- mysql存储引擎管理使用
mysql采用插件化架构,可以支持不同的存储引擎,比如myisam,innodb.本文简单的介绍mysql存储引擎的管理与使用. 1.查看mysql存储引擎:show engines; 可以看到,my ...
- Java EE业务处理流程与XML的引入
Java EE基于MVC架构的业务处理流程 MVC架构业务处理流程 XML定义 XML是可扩展标记语言,标准通用标记语言的子集,是一种用于标记电子文件使其具有结构性的标记语言.XML被设计用于数据的存 ...