Serie A Champions
To not more than one 100 of the integer string. Taken randomly from several rooms (cannot take).
Q: Is it possible to have the remaining 8 removed. Assuming can, exit Yes and choose one number for the rest of the case.
Not able to output no.
Ideas
Idea questions.
First observed. 1000 can be divisible by 8.
That means we don't care about the 4-digit situation.
It is only possible to have the number of questions said. Then it must be able to represent a 3-digit or lower number of digits. Then it is good to do, direct enumeration can be.
Let's see if there's 0.
And see if there are 8.
Then enumerate the two-digit cases. The last enumeration of three-bit numbers.
Code
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>using namespace STD;Const intMAXN = the;CharS[MAXN];intAnsintLenBOOLCHK2 (intX//Check two-digit number{CharC1 =' 0 '+x/Ten;CharC2 =' 0 '+x%Ten; for(inti =0; I < len-1; i + +) { for(intj = i+1; J < Len; J + +) {if(S[i] = = C1 && S[j] = = C2) {ans = x;return true; } } }return false;}BOOLCHK3 (intX//Check three-digit number{CharC1 =' 0 '+x/ -;CharC2 =' 0 '+ (Percent -)/Ten;CharC3 =' 0 '+x%Ten; for(inti =0; I < len-2; i + +) { for(intj = i+1; J < len-1; J + +) { for(intt = j+1; T < Len; T + +) {if(S[i] = = C1 && S[j] = = C2 && s[t] = = C3) {ans = x;return true; } } } }return false;}intMain () {scanf('%s ', s); Len =strlen(s); for(inti =0; i < Len; i + +) {if(S[i] = =' 0 ') {printf("yes\n0\n");return 0; } } for(inti =0; i < Len; i + +) {if(S[i] = =' 8 ') {printf("yes\n8\n");return 0; } } for(inti =2; I <= A; i + +) {if(Chk2 (8*i)) {printf("yes\n%d\n", ans);return 0; } } for(inti = -; I <=124; i + +) {if(Chk3 (8*i)) {printf("yes\n%d\n", ans);return 0; } }printf("no\n");return 0;}
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
Codeforces Round #306 (Div. 2) C