CF C. George and number

Source: Internet
Author: User

Http://codeforces.com/problemset/problem/387/C

Test instructions: Give you a large number, let you ask for a set, you can get this number by operation, to find the maximum number of sets, Operation: from the collection of arbitrary two number, large number placed in front of the small number placed in the back of a number in the collection, after repeated operations, the collection of only one number, this number is to you number.

Idea: The number of requests is the largest, you can let this large number of each number is a set of a number, but the set can not have 0, so in a continuous 0 before the number of a non-zero is attached.

1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 6 Charstr[1000000];7 8 intMain ()9 {Ten      while(SCANF ("%s", str)! =EOF) One     { A         intk=strlen (str); -         intans=0; -          for(inti=k-1; i>=0; i--) the         { -              intj=i; -               while(str[i]=='0') i--; -              if(j-i+1<i) ans++; +              Else if(j-i+1==i) -              { +                  BOOLflag=false; A                   for(intk=0; k<i; k++) at                  { -                      if(str[k]>str[k+i]&&str[k]!=str[k+i]) -                      { -flag=true; -ans++; -                           Break; in                      } -                      Else if(str[k]<str[k+i]&&str[k]!=str[k+i]) to                      { +ans++; -I=0; theflag=true; *                            Break; $                      }Panax Notoginseng                  } -                  if(!flag) ans++; the              } +              Else if(j-i+1>i) A              { theI=0; +ans++; -              } $         } $printf"%d\n", ans); -     } -     return 0; the}
View Code

CF C. George and number

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.