意甲冠军

到不超过一个更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的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

  9. Codeforces Round #306 (Div. 2) 550A Two Substrings

    链接:http://codeforces.com/contest/550/problem/A 这是我第一次玩cf这种比赛,前面做了几场练习,觉得div2的前面几个还是比较水的. 所以看到这道题我果断觉 ...

  10. Codeforces Round #306 (Div. 2) A B C

    题目链接:http://codeforces.com/contest/550 A 暴力一发. 代码: #include <iostream> #include <stdio.h> ...

随机推荐

  1. 【转】Android Web Server

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://vaero.blog.51cto.com/4350852/1188602 Andr ...

  2. linux下&quot;=&quot;号与&quot;==&quot;号

    <鸟哥的linux私房菜>基础学习篇P382中说,在bash中"="与"=="是同样的,都代表推断是否相等,仅仅只是因为其它语言一般写法使用&quo ...

  3. HTML介绍JS

    首先,该脚本的链接插入HTML代码: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvU2h1aVRpYW5OYWlMdW8=/font/5a6L5L2T/f ...

  4. Please read “Security” section of the manual to find out how to run mysqld as root!错误解决(转)

    2016-03-12T15:40:45.717762Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please ...

  5. [LeetCode258] Add Digits 非负整数各位相加

    题目: Given a non-negative integer num, repeatedly add all its digits until the result has only one di ...

  6. Lua Development Tools (LDT)

    http://www.eclipse.org/ldt/ Lua Development Tools (LDT) is about providing Lua developers with an ID ...

  7. ListView 实现多选/无线电

    ListView本身与无线电.多选模式.由listview.setChoiceMode设置: listview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE) ...

  8. Demo of Python &quot;Map Reduce Filter&quot;

    Here I share with you a demo for python map, reduce and filter functional programming thatowned by m ...

  9. zabbix 实现curl 显示器

    1.进入Configure->Templates 2. 新建一个模板 3.新建模板,并保存 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGFpND ...

  10. ECharts SSH+JQueryAjax+Json+JSP在数据库中的数据来填充ECharts在

    1导入包.设定SSH框架. 进口JQuery的JS包.<script src="JS/jquery-1.7.1.js"></script> 导入EChart ...