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> ...
随机推荐
- 重新想象 Windows 8 Store Apps (31) - 加密解密: 哈希算法, 对称算法
原文:重新想象 Windows 8 Store Apps (31) - 加密解密: 哈希算法, 对称算法 [源码下载] 重新想象 Windows 8 Store Apps (31) - 加密解密: 哈 ...
- 如何将IPhone应用软件发布到App Store的
转自:http://www.shtion.com/667.html 怎样将IPhone应用程序软件公布到应用程序商店? 2009年10月19日公布 分类: App store, iphone, 手机应 ...
- 【剑指offer】删除字符也出现在一个字符串
转载请注明出处:http://blog.csdn.net/ns_code/article/details/27110873 剑指offer上的字符串相关题目. 题目:输入两个字符串,从第一字符串中删除 ...
- CFileDialog
使用简单介绍
CFileDialog使用文件选择对话框:首先构造一个对象,并提供一个相应的参数,构造函数原型例如,下面的: CFileDialog::CFileDialog( BOOL bOpenFileDialo ...
- android得知----overridePendingTransition
1 Activity动画是指从一个切换activity跳到另一个activity随着电影. 它由两部分组成:第一部分是一个activity动画出口:中的第二个另一部分activity动画被访问: 于A ...
- SecureCRT使用提示
一旦itpub我写上面,我不知道这个博客的背后,我们无法上传和修改内容.好恼火啊! 原文链接:SecureCRT的几个使用方法设置 在原文的基础上,再补充几个功能: 1.最好将全部设置定制在Globa ...
- Java Enum使用演示样品枚举
package cn.edu.shu.web.util; /** * * <p> * ClassName FileType * </p> * <p> * Descr ...
- crm操作观点
using System; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messages; /// <summary> ...
- javascript倒置再次被否定作用
于javascript位反然后可以转换为浮点塑料,而不是更有效parseInt近两倍 var start = new Date().getTime(); for (var i = 0; i < ...
- 原代码,反码,解释和具体的补充 Java在>>和>>>差异
前两天分析 HashMap 的 hash 算法的时间,会见 >> 和 >>> 这两个符号.然后检查以下信息,我脑子里在某一时刻.今天遇到,我没想到居然忘 0-0.... ...