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 ...
随机推荐
- 搭建Eclipse、Resin Web开发环境
搭建Eclipse.Resin Web开发环境 一.当然是安装java开发环境 参看: Java环境的搭建 http://www.cnblogs.com/ghj1976/archive/2010/04 ...
- 中文+django1.9+python3.5一些注意点
1.模板html文件里一定要加 <!DOCTYPE html><meta http-equiv="Content-type" content="text ...
- 关于Windows API、CRT和STL二三事
1.本文编写目的 本文是为了帮助一些人弄清一些关于Windows API, C运行时程序库(CRT), 和标准C++库(STL)的基本概念.有很多人甚至是有经验的程序员在这些概念上是含糊不清的甚 ...
- Spring Batch的事务– Part 3: 略过和重试
原文:https://blog.codecentric.de/en/2012/03/transactions-in-spring-batch-part-3-skip-and-retry/ This i ...
- 精美&创意的WordPress新发主题集合
今天我整理了一些精美&创意的WordPress新发主题,它们基本上都融合了最新的设计理念,从简约到响应式,应有尽有. Engo – Smart & Minimal WordPress ...
- Camel In Action 阅读笔记 第一部分概述 + 第一章概述 认识Camel
第一部分: 最开始的一小步 Apache Camel 是一个开源集成框架,其目的是让系统集成变得更加简便,在本书的第一章中,我们会为您介绍它并向您展示它是如何在大型企业应用中做好集成工作.您也会了解到 ...
- golang实现ios推送
生成pem文件 打开Keychain Access 导出推送证书和私钥 推送证书 cert.p12 私钥 key.p12 导出.pem文件 转换推送证书 openssl pkcs12 -clcerts ...
- NServiceBus-网关和多站点分布
多站点部署的企业的数量.净系统由于增加的挑战高可用性和用户要求更快的响应时间,服务器和数据访问更接近. RPC技术迅速陷入困境在这些环境中,使机器在同一个站点和远程站点看起来是一样的. 在这些情况下, ...
- c++builder 重载WindowProc、WndProc 截获消息
c++builder 重载WindowProc.WndProc 截获消息 方法一WindowProc void __fastcall myWindowProc(Messages::TMessage ...
- VS2008 工程中部分文件不参与编译 从生成中排除【Worldsing笔记】
Visual Studio 2008 .VS2008.VC2008工程源文件配置.编译配置 有时编写代码时,往往存在这样的需求(或是希望有这样的功能):一个工程经过不共同的配置实现不同的版本或是功 ...