Sha 11489 integer game (logical reasoning)

Source: Internet
Author: User

Click to open the question link

This question cannot be viewed as violent. You can only find the rule and push the formula.

The question requires that the sum of the remaining numbers after each fetch is a multiple of 3. How many of the elements that constitute the remaining sum are multiples of 3, if there are count in the statistics, all the remaining count except this Count must not be divisible by 3, but the number and the sum of the three cannot be divisible by 3. Imagine, if I take one of them, then the sum of all the remaining numbers cannot be divided by 3, which means the elements cannot be obtained. Therefore, each operation can only be an element multiple of 3, if you know that an individual does not have an element that is a multiple of 3, you will lose !!!

# Include <iostream> # include <cstring> using namespace STD; int main (INT argc, char * argv []) {int t, n, I, j, sum, count, sum1, count1, TT = 0; char a [10005], ans; CIN> T; while (t --) {CIN> A; ans = 'T '; for (I = COUNT = sum = 0; I <strlen (a); I ++) {sum + = A [I]-'0 '; if (A [I]-'0') % 3 = 0) Count ++;} for (I = 0; I <strlen (a); I ++) {sum1 = sum-(A [I]-'0'); count1 = count; If (sum1% 3 = 0) {If (A [I]-'0') % 3 = 0) count1 --; If (count1% 2 = 0) {ans ='s '; break ;}}cout <"case" <++ TT <":" <ans <Endl;} return 0 ;}

 

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.