Hangzhou Computer Program Design Competition (2016 ' 12)-Network synchronization 1002

Source: Internet
Author: User

Increment number

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 0 Accepted Submission (s): 0

problem DescriptionIf a positive integer a, adjacent bits always satisfy the lower than equal to the high, it is called the increment number.
For example: 1223,667 is the increment number.
now there is a positive integer X, how many positive integer a satisfies 1<=a<=x, and a is incremented. InputThe first line of input data is a positive integer T (1<=t<=20) that represents the number of groups of test data.
Next T line, one positive integer X (1<=x<=100000000) per line. Outputfor each set of data, output a row of answers, see the output sample. Sample Input35 - - Sample Output5 - Wu
/** * @Author: H s-j * @DateTime: 2016-12-24 13:06:57 * @Description: Hdu-2*/#include<functional>#include<algorithm>#include<iostream>#include<fstream>#include<sstream>#include<iomanip>#include<numeric>#include<cstring>#include<cassert>#include<cstdio>#include<string>#include<vector>#include<bitset>#include<queue>#include<stack>#include<cmath>#include<ctime>#include<list>#include<Set>#include<map>using namespacestd;Long Longdp[Ten][Ten] = {0};intdig[111];intCountLong Longm) {intnum =1;  while(M/Ten) {        ++num; M/=Ten; }    returnnum;}voidCount_1 (Long LongMintflag) {     while(m) {Dig[flag]= (m%Ten); ++Flag; M/=Ten; }}    voidinit () { for(inti =1; I <Ten; ++i) { for(intj =0; J <Ten; ++j) {if(i = =1) {Dp[i][j]=J; }            Else {                if(J = =0) Dp[i][j] = (Dp[i-1][9]); ElseDP[I][J] = (Dp[i][j-1] + dp[i-1][9]-Dp[i-1][j-1]); }        }    }}intMain () {init (); intN; CIN>>N;  while(n--) {        Long Longx; CIN>>x; intnum; Num=count (x); Count_1 (x,1); Long LongAns =0;  for(inti = num; i >0; --i) {if(I < num && Dig[i] < Dig[i +1]) Break; if(i = =1) {                if(num = =1) ans + = dig[1]; ElseAns + = (Dig[i]-dig[i +1] +1); }            Else {                if(i = =num) {ans+ = Dp[i][dig[i]-1]; }                Else{ans+ = (Dp[i][dig[i]-1]-Dp[i][dig[i +1] -1]); } }} cout<< ans <<Endl; }    return 0;}

Hangzhou Computer Program Design Competition (2016 ' 12)-Network synchronization 1002

Related Article

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.