zoukankan      html  css  js  c++  java
  • 题解 [51nod1385] 凑数字

    题面

    解析

    首先设(n)(l)位,

    那么对于前(l-1)位,(0)~(9)都是要选上的,

    而对于最高位上的数(x),(1)~(x-1)也是要选上的.

    到这里就有了(10*(l-1)+x-1)

    而我们还要考虑最高位的数(x)能不能省(比如说样例就能省).

    设一个数(sum)(l)位,每一位都为(x),

    如果省掉的话,我们能表示的数就一定小于(sum),

    因为(sum)有一位一定表示不出.

    因此我们只需要判断(n)(sum)的大小关系即可.

    code:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #define filein(a) freopen(a".cpp","r",stdin)
    #define fileout(a) freopen(a".cpp","w",stdout);
    using namespace std;
    
    inline int read(){
    	int sum=0,f=1;char c=getchar();
    	while((c<'0'||c>'9')&&c!=EOF){if(c=='-') f=-1;c=getchar();}
    	while(c>='0'&&c<='9'&&c!=EOF){sum=sum*10+c-'0';c=getchar();}
    	return sum*f;
    }
    
    const int N=100001;
    int n,m;
    char s[N];
    
    int main(){
    	cin>>s;n=strlen(s);
    	int ans=(n-1)*10+s[0]-'1',ok=1;
    	for(int i=0;i<n-1;i++){
    		if(s[i+1]<s[i]){ok=0;break;}
    		else if(s[i+1]>s[i]) break;
    	}
    	ans+=ok;
    	printf("%d
    ",ans);
    	return 0;
    }
    
    
  • 相关阅读:
    Attributes in C#
    asp.net C# 时间格式大全
    UVA 10518 How Many Calls?
    UVA 10303 How Many Trees?
    UVA 991 Safe Salutations
    UVA 10862 Connect the Cable Wires
    UVA 10417 Gift Exchanging
    UVA 10229 Modular Fibonacci
    UVA 10079 Pizza Cutting
    UVA 10334 Ray Through Glasses
  • 原文地址:https://www.cnblogs.com/zsq259/p/11409336.html
Copyright © 2011-2022 走看看