意甲冠军

到不超过一个更100该整数字符串。采取随机从数间(不能拿)。

问:是否有可能被剩下8除尽。假设能,出口YES和任选一个数字的其余病例的。

不能够,输出NO。

思路

想法题。

首先观察到。1000能够整除8。

也就是说我们能够不关心4位数的情况。

仅仅要有可能存在题目说的数。那么它一定能够表示成3位数或更低的位数。那么就好办了,直接枚举就可以。

先看是否有0.

再看是否有8.

接着枚举两位数的情况。最后枚举三位数的情况。

代码

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. #include <iostream>
  5. using namespace std;
  6. const int maxn = 110;
  7. char s[maxn];
  8. int ans;
  9. int len;
  10. bool chk2(int x)//检查两位数
  11. {
  12. char c1 = '0'+x/10;
  13. char c2 = '0'+x%10;
  14. for(int i = 0 ; i < len-1 ; i ++) {
  15. for(int j = i+1 ; j < len ; j ++) {
  16. if(s[i] == c1 && s[j] == c2) {
  17. ans = x;
  18. return true;
  19. }
  20. }
  21. }
  22. return false;
  23. }
  24. bool chk3(int x)//检查三位数
  25. {
  26. char c1 = '0'+x/100;
  27. char c2 = '0'+(x%100)/10;
  28. char c3 = '0'+x%10;
  29. for(int i = 0 ; i < len-2 ; i ++) {
  30. for(int j = i+1 ; j < len-1 ; j ++) {
  31. for(int t = j+1 ; t < len ; t ++) {
  32. if(s[i] == c1 && s[j] == c2 && s[t] == c3) {
  33. ans = x;
  34. return true;
  35. }
  36. }
  37. }
  38. }
  39. return false;
  40. }
  41. int main()
  42. {
  43. scanf("%s",s);
  44. len = strlen(s);
  45. for(int i = 0 ; i < len ; i ++) {
  46. if(s[i] == '0') {
  47. printf("YES\n0\n");
  48. return 0;
  49. }
  50. }
  51. for(int i = 0 ; i < len ; i ++) {
  52. if(s[i] == '8') {
  53. printf("YES\n8\n");
  54. return 0;
  55. }
  56. }
  57. for(int i = 2 ; i <= 12 ; i ++) {
  58. if(chk2(8*i)) {
  59. printf("YES\n%d\n",ans);
  60. return 0;
  61. }
  62. }
  63. for(int i = 13 ; i <= 124 ; i ++) {
  64. if(chk3(8*i)) {
  65. printf("YES\n%d\n",ans);
  66. return 0;
  67. }
  68. }
  69. printf("NO\n");
  70. return 0;
  71. }

版权声明:本文博客原创文章,博客,未经同意,不得转载。

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. 重新想象 Windows 8 Store Apps (31) - 加密解密: 哈希算法, 对称算法

    原文:重新想象 Windows 8 Store Apps (31) - 加密解密: 哈希算法, 对称算法 [源码下载] 重新想象 Windows 8 Store Apps (31) - 加密解密: 哈 ...

  2. 如何将IPhone应用软件发布到App Store的

    转自:http://www.shtion.com/667.html 怎样将IPhone应用程序软件公布到应用程序商店? 2009年10月19日公布 分类: App store, iphone, 手机应 ...

  3. 【剑指offer】删除字符也出现在一个字符串

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/27110873 剑指offer上的字符串相关题目. 题目:输入两个字符串,从第一字符串中删除 ...

  4. CFileDialog 使用简单介绍

    CFileDialog使用文件选择对话框:首先构造一个对象,并提供一个相应的参数,构造函数原型例如,下面的: CFileDialog::CFileDialog( BOOL bOpenFileDialo ...

  5. android得知----overridePendingTransition

    1 Activity动画是指从一个切换activity跳到另一个activity随着电影. 它由两部分组成:第一部分是一个activity动画出口:中的第二个另一部分activity动画被访问: 于A ...

  6. SecureCRT使用提示

    一旦itpub我写上面,我不知道这个博客的背后,我们无法上传和修改内容.好恼火啊! 原文链接:SecureCRT的几个使用方法设置 在原文的基础上,再补充几个功能: 1.最好将全部设置定制在Globa ...

  7. Java Enum使用演示样品枚举

    package cn.edu.shu.web.util; /** * * <p> * ClassName FileType * </p> * <p> * Descr ...

  8. crm操作观点

    using System;     using Microsoft.Xrm.Sdk;     using Microsoft.Crm.Sdk.Messages; /// <summary> ...

  9. javascript倒置再次被否定作用

    于javascript位反然后可以转换为浮点塑料,而不是更有效parseInt近两倍 var start = new Date().getTime(); for (var i = 0; i < ...

  10. 原代码,反码,解释和具体的补充 Java在&gt;&gt;和&gt;&gt;&gt;差异

    前两天分析 HashMap 的 hash 算法的时间,会见 >> 和 >>> 这两个符号.然后检查以下信息,我脑子里在某一时刻.今天遇到,我没想到居然忘  0-0.... ...