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