zoukankan      html  css  js  c++  java
  • 排列组合——hdu 4151

    特殊数

    排列组合联系好题

    如:9876543

    先算特殊数有6位数有几种

    在统计有7位时有几个

    View Code
    #include<stdio.h>
    #include<string.h>
    #include<iostream>
    #include<stack>
    using namespace std;

    bool hash[10];

    __int64 p(__int64 a,__int64 b)
    {
    if(a>b)return 0;
    __int64 all=1;
    while(a--)
    {
    all=all*b;
    b--;
    }
    return all;
    }

    __int64 sum(__int64 n)
    {
    __int64 add=0,i;
    for(i=0;i<n;i++)
    {
    if(hash[i])add++;
    }
    return add;
    }

    int main()
    {
    __int64 n,temp;
    while(scanf("%I64d",&n)!=EOF)
    {
    if(n<0)
    {
    printf("0\n");
    continue;
    }
    memset(hash,0,sizeof(hash));

    __int64 len=0,i;
    temp=n;
    while(temp)
    {
    len++;
    temp=temp/10;
    }

    __int64 all=0;
    for(i=0;i<len-1;i++)
    {
    all+=9*p(i,9);
    }


    temp=n;
    __int64 add=9,tlen=len-1;

    stack<int>ss;
    while(temp)
    {
    ss.push(temp%10);
    temp=temp/10;
    }

    __int64 first=1;
    while(!ss.empty())
    {
    temp=ss.top();
    ss.pop();

    if(temp!=0)
    {
    if(first==1)
    {
    all+=(temp-1-sum(temp))*p(tlen,add);
    first=0;
    }else
    all+=(temp-sum(temp))*p(tlen,add);
    }
    else
    {
    // hash[0]=1;
    }

    if(hash[temp]==0)
    hash[temp]=1;
    else
    break;
    tlen--;
    add--;
    }
    printf("%I64d\n",all);
    }

    return 0;
    }



  • 相关阅读:
    SELFJOIN
    lLinux编程大全
    一个基础但是隐晦的c++语法问题
    cocos2dx内存优化
    iOS和android游戏纹理优化和内存优化(cocos2dx)
    STL学习小结
    C++11
    游戏资源打包
    C++ '__FILE__' and '__LINE__
    Cocos2dx纹理优化的一些方案
  • 原文地址:https://www.cnblogs.com/huhuuu/p/2345281.html
Copyright © 2011-2022 走看看