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> ...
随机推荐
- 使用ZeroMQ(clrzmq)实现异步通信
ZeroMQ是对Socket的封装,通过组合多种类型的结点可以实现复杂的网络通信模式.而且ZeroMQ设计简单,可以有多种平台实现,对于跨平台项目是一个福音. clrzmq是ZeroMQ的C#语言的实 ...
- 【leetCode百题成就】Gas Station解题报告
题目: There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. ...
- OpenCV在MFC图像控件内显示图像
1.依照文章<OpenCV+MFC显示图像>,完毕配置. 2.创建对应的图像控件,button控件. 3.进行类型转换. 在当前OpenCV2版本号内,图像格式为cv::Mat ,而该格式 ...
- cocos2d-x于android在call to OpenGL ES API with no current context
一.问题: 正在使用JNI离Java(Android)侧 打回来C++(Cocos2d-x)该函数返回消息.Cocos2d-x花掉了 看看 Eclipse的Log中.显示 有 call to Open ...
- hdu2377Bus Pass(构建更复杂的图+spfa)
主题链接: 啊哈哈,点我点我 思路: 题目是给了非常多个车站.然后要你找到一个社区距离这些车站的最大值最小..所以对每一个车站做一次spfa.那么就得到了到每一个社区的最大值,最后对每一个社区扫描一次 ...
- 【Web探索之旅】第三部分第二课:IP地址和域名
内容简介 1.第三部分第二课:IP地址和域名 2.第三部分第三课预告:协议 第三部分第二课:IP地址和域名 上一课我们说了在Web之中,全球各地有无数台机器,有些充当客户机,有些作为服务器. 那么这些 ...
- ASIHTTPRequest 对GET POST 请求简包
1.ASIHTTPRequest一个简短的引论 github下载链接https://github.com/pokeb/asi-http-request 2.ASIHTTPRequest 对GET和PO ...
- Hibernate 映射字段问题[ImprovedNamingStrategy]
Hibernate 使用JPA 对于映射有3种规则能够配置:DefaultNamingStrategy,ImprovedNamingStrategy,EJB3NamingStrategy 这里仅仅说I ...
- 【YouVersion】 The Bible 圣经App
[YouVersion] The Bible 圣经 App 今天向大家郑重推荐一款非常棒的圣经App : <The Bible> YouVersion 团队开发的全球下载量和安装数目第 ...
- 读书时间《JavaScript高级程序设计》三:函数,闭包,作用域
上一次看了第6章,面向对象.这里接着看第7章. 第7章:函数表达式 定义函数有两种方式:函数声明.函数表达式 //函数声明 function functionName(arg0,arg1,arg2){ ...