Codeforces Round #306 (Div. 2) C. Divisibility by Eight 暴力
C. Divisibility by Eight
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/550/problem/C
Description
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes.
Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-negative integer, doesn't have leading zeroes and is divisible by 8. After the removing, it is forbidden to rearrange the digits.
If a solution exists, you should print it.
Input
Output
Print "NO" (without quotes), if there is no such way to remove some digits from number n.
Otherwise, print "YES" in the first line and the resulting number after removing digits from number n in the second line. The printed number must be divisible by 8.
If there are multiple possible answers, you may print any of them.
Sample Input
3454
Sample Output
YES
344
HINT
题意
给你一个最多100位的数,让你去掉一些数,然后让这个数是8的倍数
题解:
首先,成为8的倍数,只要末尾3位数是8的倍数就好(8×125=1000)
于是我们只用判定三位数就好,然后特判一位数和两位数的情况
暴力枚举三位数的情况就好啦~
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 2000001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** string s;
ll ans;
ll solve(char A,char B,char C)
{
ll ans=(A-'')*+(B-'')*+(C-'');
return ans;
}
int main()
{
//test;
char O='';
cin>>s;
for(int i=;i<s.size();i++)
{
if(s[i]==''||s[i]=='')
{
cout<<"YES"<<endl;
cout<<s[i]<<endl;
return ;
}
}
if(s.size()==)
{
ans=s[]-'';
if(ans%==)
{
printf("YES\n");
cout<<ans<<endl;
return ;
}
printf("NO\n");
return ;
}
if(s.size()==)
{
if(solve(O,O,s[])%==)
{
cout<<"YES"<<endl;
cout<<solve(O,O,s[])<<endl;
return ;
}
if(solve(O,s[],s[])%==)
{
cout<<"YES"<<endl;
cout<<solve(O,s[],s[])<<endl;
return ;
}
if(solve(O,O,s[])%==)
{
cout<<"YES"<<endl;
cout<<solve(O,O,s[])<<endl;
return ;
}
printf("NO\n");
return ;
} for(int j=;j<s.size();j++)
{
for(int k=j+;k<s.size();k++)
{
if(solve(O,s[j],s[k])%==)
{
cout<<"YES"<<endl;
cout<<solve(O,s[j],s[k])<<endl;
return ;
}
}
}
for(int i=;i<s.size();i++)
{
for(int j=i+;j<s.size();j++)
{
for(int k=j+;k<s.size();k++)
{
if(solve(s[i],s[j],s[k])%==)
{
cout<<"YES"<<endl;
cout<<solve(s[i],s[j],s[k])<<endl;
return ;
}
}
}
}
cout<<"NO"<<endl;
return ;
}
Codeforces Round #306 (Div. 2) C. Divisibility by Eight 暴力的更多相关文章
- 数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight
题目传送门 /* 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 */ #include <cstdio> #include <a ...
- Codeforces Round #306 (Div. 2)A B C D 暴力 位/暴力 暴力 构造
A. Two Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #486 (Div. 3) E. Divisibility by 25
Codeforces Round #486 (Div. 3) E. Divisibility by 25 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...
- DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad
题目传送门 /* DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : */ #include <cstdio> #include <iostream&g ...
- 水题 Codeforces Round #306 (Div. 2) A. Two Substrings
题目传送门 /* 水题:遍历一边先找AB,再BA,再遍历一边先找BA,再AB,两种情况满足一种就YES */ #include <cstdio> #include <iostream ...
- Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索
Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec Memory Limit: 512 MBSubmit: xxx ...
- 「日常训练」Divisibility by Eight(Codeforces Round 306 Div.2 C)
题意与分析 极简单的数论+思维题. 代码 #include <bits/stdc++.h> #define MP make_pair #define PB emplace_back #de ...
- Codeforces Round #306 (Div. 2) E. Brackets in Implications 构造
E. Brackets in Implications Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...
- Codeforces Round #306 (Div. 2) D. Regular Bridge 构造
D. Regular Bridge Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...
随机推荐
- nslookup返回信息说明
先看一个示例: 如上图,我们把输出结果分成三部分,下面分别来描述: 第一部分: 这里是我们本机的DNS服务器信息. 客户机先到主DNS Server进行连接查询,结果发现异常,连接失败,于是出 ...
- angularJS+requireJS并集成karma测试实践
最近在为下一个项目做前端技术选型,Angular是必须要用的(BOSS指定,个人感觉也不错,开发效率会很高).由于需要加载的JS很多,所以打算看看angular和requirejs一起用会怎么样.在g ...
- iOS学习笔记之回调(一)
什么是回调 看了好多关于回调的解释的资料,一开始总觉得这个概念理解起来有点困难,可能是因为自己很少遇到这种类型的调用吧.探索良久之后,才算有点启发,下面是自己的一点理解. 我们知道,在OSI网络七层模 ...
- chrome 浏览器 开发者工具 性能检测 参数解释
Sending is time spent uploading the data/request to the server. It occurs between blocking and waiti ...
- NServiceBus教程-持久化
NServiceBus的各种特性需要持久性.其中有超时.传奇和订阅存储. 四个持久化技术在NServiceBus在使用: RavenDB nHibernate 内存中 MSMQ 读到安装Raven D ...
- create_project.py报错问题,建议用回python2.7
d:\DevTool\cocos2d-x-2.2.2\cocos2d-x-2.2.2\tools\project-creator\create_project.py 报错 d:\DevTool\coc ...
- 如何使cron任务出错时发邮件
如果设置了 MAILTO,cron就会将任务的标准输出和标准错误输出重定向到邮箱(即发送邮件).但如果只想接到错误报警邮件 -- 即任务正常执行时不发送,只在出错时发送 -- 应该怎么实现呢? 方法很 ...
- Objective-C 学习笔记(1)
文件描述: .h 类的声明文件,用户声明变量.函数(方法) .m 类的实现文件,用户实现.h中的函数(方法) 类的声明使用关键字 @interface.@end 类的实现使用关键字@implement ...
- HDU 5858 Hard problem (数学推导)
Hard problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5858 Description cjj is fun with ...
- 应用dom4j读取xml的例子
1. 样例xml <?xml version="1.0" encoding="UTF-8"?> <students> <stude ...