Codeforces Round #306 (Div. 2) C
意甲冠军
到不超过一个更100该整数字符串。采取随机从数间(不能拿)。
问:是否有可能被剩下8除尽。假设能,出口YES和任选一个数字的其余病例的。
不能够,输出NO。
思路
想法题。
首先观察到。1000能够整除8。
也就是说我们能够不关心4位数的情况。
仅仅要有可能存在题目说的数。那么它一定能够表示成3位数或更低的位数。那么就好办了,直接枚举就可以。
先看是否有0.
再看是否有8.
接着枚举两位数的情况。最后枚举三位数的情况。
代码
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn = 110;
char s[maxn];
int ans;
int len;
bool chk2(int x)//检查两位数
{
char c1 = '0'+x/10;
char c2 = '0'+x%10;
for(int i = 0 ; i < len-1 ; i ++) {
for(int j = i+1 ; j < len ; j ++) {
if(s[i] == c1 && s[j] == c2) {
ans = x;
return true;
}
}
}
return false;
}
bool chk3(int x)//检查三位数
{
char c1 = '0'+x/100;
char c2 = '0'+(x%100)/10;
char c3 = '0'+x%10;
for(int i = 0 ; i < len-2 ; i ++) {
for(int j = i+1 ; j < len-1 ; j ++) {
for(int t = j+1 ; t < len ; t ++) {
if(s[i] == c1 && s[j] == c2 && s[t] == c3) {
ans = x;
return true;
}
}
}
}
return false;
}
int main()
{
scanf("%s",s);
len = strlen(s);
for(int i = 0 ; i < len ; i ++) {
if(s[i] == '0') {
printf("YES\n0\n");
return 0;
}
}
for(int i = 0 ; i < len ; i ++) {
if(s[i] == '8') {
printf("YES\n8\n");
return 0;
}
}
for(int i = 2 ; i <= 12 ; i ++) {
if(chk2(8*i)) {
printf("YES\n%d\n",ans);
return 0;
}
}
for(int i = 13 ; i <= 124 ; i ++) {
if(chk3(8*i)) {
printf("YES\n%d\n",ans);
return 0;
}
}
printf("NO\n");
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
Codeforces Round #306 (Div. 2) C的更多相关文章
- 数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight
题目传送门 /* 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 */ #include <cstdio> #include <a ...
- 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 #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 ...
- 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/ ...
- Codeforces Round #306 (Div. 2) B. Preparing Olympiad dfs
B. Preparing Olympiad Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550 ...
- Codeforces Round #306 (Div. 2) A. Two Substrings 水题
A. Two Substrings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...
- Codeforces Round #306 (Div. 2) 550A Two Substrings
链接:http://codeforces.com/contest/550/problem/A 这是我第一次玩cf这种比赛,前面做了几场练习,觉得div2的前面几个还是比较水的. 所以看到这道题我果断觉 ...
- Codeforces Round #306 (Div. 2) A B C
题目链接:http://codeforces.com/contest/550 A 暴力一发. 代码: #include <iostream> #include <stdio.h> ...
随机推荐
- 三——第二部分——第二篇论文 计划建设SQL Server镜像
本文接着前面的章节:SQL Server镜像简单介绍 本文出处:http://blog.csdn.net/dba_huangzj/article/details/27203053 俗话说:工欲善其事必 ...
- 采用truelicense进行Java规划license控制 扩展可以验证后,license 开始结束日期,验证绑定一个给定的mac住址
采用truelicense进行Java规划license控制 扩展可以验证后,license 开始结束日期,验证绑定一个给定的mac住址. Truelicense 它是一个开源java license ...
- 制作service服务,shell脚本小例子(来自网络)
事先准备工作:源码安装apache .安装目录为/usr/local/httpd 任务需求:1.可通过 service httpd start|stop|status|restart 命令对服务进行控 ...
- poj 2408 Anagram Groups(hash)
id=2408" target="_blank" style="">题目链接:poj 2408 Anagram Groups 题目大意:给定若干 ...
- JAVA实现DAO基本层CRUD操作
随着shh2各种操作方便框架.越来越多JAVA WEB效率,可是,假设在不了解这些框架使用的场合的情况下,一拿到项目就盲目地选择这些框架进行系统架构的搭建,就有可能造成非常多不是必需的资源浪费. 在项 ...
- 具体的了解“>/dev/null 2>&1”
Linux系统中不管是crontab里面.还是平时使用的命令.常常会碰到">/dev/null 2>&1".比方说:在Crontab Job里面,假设不想发送邮 ...
- hive内置函数大全
====================================== 一.关系函数 1.等值比較:= 语法:A=B 操作类型:全部基本类型 2.不等值比較:<> 语 ...
- Android开发技巧——PagerAdapter再简单的包
再次内容View的ViewPager该适配器PagerAdapter简包,支持List数据与SparseArray数据.随着更新的浏览功能. 首先,首先贴上顶部抽象类代码: /* * Date: 14 ...
- HDU 2454 Degree Sequence of Graph G(Havel定理 推断一个简单图的存在)
主题链接:pid=2454">http://acm.hdu.edu.cn/showproblem.php?pid=2454 Problem Description Wang Haiya ...
- Android+NDK+OpenGLES开发环境配置
1.资源 (1).Android的eclipse开发环境 我用adt-bundle-windows-x86.官方主页就能下载.这是一个打包的版本号,直接执行eclipse.exe你可以开始 (2).N ...