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

    Extension Method: Return another string if string is null or emptyJust a tiny little extension metho ...

  2. 数学概念 z

    数学是很难的科学,但因为它是科学家用数学来解释宇宙的语言,我们无可避免的要学习它.看看下面的这些 GIF 动图,它们提供了视觉的方式来帮助你理解各种数学技巧. 1.椭圆的画法 2.杨辉三角问题(Pas ...

  3. 17、Wi-Fi Direct

    Wi-Fi Direct简介 从Android4.0(API Level=14)开始,允许通过Wi-Fi模块在两个移动设备之间建立直接连接(这种技术称为Wi-Fi Direct),这种连接不需要无线路 ...

  4. angularjs $swipe调用方法

    angularjs 的$swipe,用法: $swipe.bind(angular.element(document),{ start: function(pos) { }, move: functi ...

  5. 第一个UI脚本--python+selenium

    之前一直是用java+selenium做自动化测试的,最近因为工作需要,需要用pyhton+selenium去实现,于是就赶驴上架,熟悉了一下python的语法和脚本的编写过程,下面是一个简单的脚本, ...

  6. VS 2013 EFSQLITE

    在 vs 2013 上用 1.NuGet程序包来获取,它也会自动下载EF6的包 :system.Data.sqlite 他会自动下载 其它几个需要的包. 2.在Sqlite官网上下载对应的版本:htt ...

  7. PHP.ini 配置文件解析

    [PHP] ;;;;;;;;;;;;;;;;;;;; About php.ini   ;;;;;;;;;;;;;;;;;;;;; PHP's initialization file, generall ...

  8. DTD 简介

    文档类型定义(DTD)可定义合法的XML文档构建模块.它使用一系列合法的元素来定义文档的结构.DTD 可被成行地声明于 XML 文档中,也可作为一个外部引用. 内部的 DOCTYPE 声明 假如 DT ...

  9. java 编写hadoop程序中使用第三方libxx.so库

    在使用java编写hadoop处理程序时遇到了,java使用依赖的第三方libxx.so库的情况,找到了一种可行的方法,记录一下,希望对别人也有帮助: 加入需要使用的lib库为libxxx.so 1. ...

  10. SharePoint咨询师之路:备份和恢复系列二 - 备份服务器场

    本系列包括: 备份服务器场和配置 备份web和服务应用程序 备份内容数据库 备份网站集 备份自定义项 根据“SharePoint咨询师之路:备份和恢复系列--制定备份计划”我们制定了一下备份计划如下: ...