Codeforces Round #306 (Div. 2) C

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.