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

The single line of the input contains a non-negative integer n. The representation of number n doesn't contain any leading zeroes and its length doesn't exceed 100 digits.

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 暴力的更多相关文章

  1. 数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight

    题目传送门 /* 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 */ #include <cstdio> #include <a ...

  2. 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 ...

  3. Codeforces Round #486 (Div. 3) E. Divisibility by 25

    Codeforces Round #486 (Div. 3) E. Divisibility by 25 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...

  4. DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad

    题目传送门 /* DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : */ #include <cstdio> #include <iostream&g ...

  5. 水题 Codeforces Round #306 (Div. 2) A. Two Substrings

    题目传送门 /* 水题:遍历一边先找AB,再BA,再遍历一边先找BA,再AB,两种情况满足一种就YES */ #include <cstdio> #include <iostream ...

  6. 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 ...

  7. 「日常训练」Divisibility by Eight(Codeforces Round 306 Div.2 C)

    题意与分析 极简单的数论+思维题. 代码 #include <bits/stdc++.h> #define MP make_pair #define PB emplace_back #de ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. LR之错误处理

    1.脚本的健壮性 2.VuGen的处理机制 3.lr_continue_on_error函数 4.示例代码

  2. centos7虚拟机无法上网的解决办法

    今天在VMware虚拟机中经过千辛万苦终于安装好了centos7..正兴致勃勃的例行yum update 却发现centos系统貌似默认网卡没配置好,反馈无法联网.经过一番研究,终于让centos连上 ...

  3. PHP 获取网页301|302真实地址

    function getRealURL($url){ $header = get_headers($url,1); if (strpos($header[0],'301') || strpos($he ...

  4. html --- SVG --- javascript --- 旋转矩形

    可缩放矢量图形(英语:Scalable Vector Graphics,SVG)是基于可扩展标记语言(XML), 用于描述二维矢量图形的一种图形格式.SVG由W3C制定,是一个开放标准. 在 Inte ...

  5. Apriori算法例子

    1 Apriori介绍 Apriori算法使用频繁项集的先验知识,使用一种称作逐层搜索的迭代方法,k项集用于探索(k+1)项集.首先,通过扫描事务(交易)记录,找出所有的频繁1项集,该集合记做L1,然 ...

  6. Careerup上的简历模板

    So this is what a GOOD resume look like http://www.careercup.com/resume (需FQ)

  7. extjs 学习笔记(二)

    EXTJS实用开发指南 1. 要使用ExtJS 框架的页面中一般包括下面几句: <link rel="stylesheet" type="text/css" ...

  8. noip模拟赛 软件software

    地图上的 n个城市,由 n-1条道路连接,且任意两个城市连通.除 1号城市之外的每个都有 一台计算机,安装软件号城市之外的每个都有 一台计算机,安装软件一个 自己的安装时间.住在 1号城市的蒟蒻要给这 ...

  9. js冲突

    bundles.Add(new ScriptBundle("~/bundles/jquery").Include(//"~/Scripts/modernizr-2.6.2 ...

  10. 第二百一十三天 how can I 坚持

    今天去爬山了,百望山,山好矮,绕来绕去也挺远的,山上有座庙,佘太君庙,还有个望京楼,还看到了个写书法的,不懂,但很崇拜. 今天玩LOL全输了,咋搞的呢. 还有买了点排骨,都没吃完. 下周去爬凤凰岭. ...