" Topic link " click here~~
"The main topic "
Give a number not exceeding 100 digits, ask whether to delete several numbers, the remaining number can be divisible by 8
" problem-solving ideas ": There is a nature: if a number after three can be divisible by 8, then this number can be divisible by 8
Proof: Give an example of a 5-digit number,
For example
_____ _____ __ __ __ __ ___
Abcde=ab000+cde=1000xab+cde=8x125xab+cde
Obviously, 8x125xab must be a multiple of 8 or 125, so when the CDE can be divisible by 8 or 125, the five-digit ABCDE can be divisible by 8 or 125. The number of digits is the same, mainly 1000=125*8
So as long as you enumerate the three bits
Code:
#include <bits/stdc++.h>using namespace Std;int main () {char str[110]; while (CIN>>STR) {bool Ok=false; int Len=strlen (str); for (int i=0; i<len; ++i) {if ((str[i]-' 0 ')%8==0) {puts ("yes"); cout<< (str[i]-' 0 ') <<endl; return 0; }} for (int i=0, i<len; ++i) {for (int j=i+1; j<len; ++j) { if ((str[i]-' 0 ') *10+ (str[j]-' 0 ')) (%8==0) {puts ("yes"); cout<< ((str[i]-' 0 ') *10+ (str[j]-' 0 ')) <<endl; return 0; }}} for (int i=0, i<len; ++i) {for (int j=i+1; j<len; ++j) { for (int k=j+1; k<len; ++k) {if (((str[i]-' 0 ') *100+ (str[j]-' 0 ') *10+str[ k]-' 0 ')%8==0) { Puts ("YES"); cout<< ((str[i]-' 0 ') *100+ (str[j]-' 0 ') *10+str[k]-' 0 ') <<endl; return 0; }}}} puts ("NO"); }}
The official problem is to use DP, some trouble.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Codeforces 550C divisibility by Eight (enumeration)