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> ...
随机推荐
- android 4.0 中出错 java.lang.UnsupportedOperationException
在android4.0中 画图的时候使用: canvas.clipPath(path, Region.Op.XOR); 报错 java.lang.UnsupportedOperationExcept ...
- ZOJ 3734 LIKE vs CANDLE
题目意思:(13年长沙站的一道水DP,本人也去了,当时太水笔) 说俩个人竞争选票,每个人可以随机选择支持谁.每个人带有权重不同. 现在已经结束了投票阶段,你一个骇客 支持LIKE 你写了一个软件可以 ...
- 输出无名空数组---精android、IOS App应用服务程序开发
直接输出 [] 示例文件_samples/app/array_null.json在轻开平台的_samples/app/文件夹下 太Easy.无法写出很多其它的内容,大家还是自己试试吧! ! ! 相关资 ...
- sql分隔字符串数组
declare @relation_code nvarchar(1024) set @relation_code = '#10000#10002' set @relation_code=substri ...
- 隐藏快捷方式扩展名(.lnk)
自从装了Windows 7操作系统以后,有一个问题一直困扰着我.当我去掉“目录选项中”的“隐藏已知文件类型的扩展名”选项的“√”之后,桌面上的快捷方式的扩展名也出来了,看上去非常不爽.记得在XP.Vi ...
- redmine 出口中国的乱码
pdf 这是redmine的bug.必须在个人账户更改将设立中国语文,足够的人才来解决. 顺便说一下,提示.以下更改文件的方法是无效的 /home/redmine/redmine-2.5.1/lib/ ...
- 图表引擎AChartEngine 二
这几天项目涉及到android图表绘制,网上找的Demo都是大同小异,也就如上篇博文所写的一样是基本函数的实现.可是所有能找到的Demo都和设计图不符.木有办法,Leader发话啦,万不得已的情况下不 ...
- 香蕉派路由功Openwrt、Android功耗对照測试
路由这个东西是要长期通电使用的,所以功耗也是须要关注的.如今香蕉派路由已经有了openwrt和android两个 系统,这两个系统的功耗是否一样呢? 測试工具:QUIGG的德国产功耗測试仪一个.手机充 ...
- Base64加密解密原理以及代码实现
1. Base64使用A--Z,a--z,0--9,+,/ 这64个字符. 2. 编码原理:将3个字节转换成4个字节( (3 X 8) = 24 = (4 X 6) )先读入3个字节,每读一个字 ...
- JXL组件生成报告错误(两)
JXL组件生成报告 1.详细报错例如以下: usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -non ...