zoukankan      html  css  js  c++  java
  • poj1496——组合数学

    poj1496——组合数学

    Word Index
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 4740   Accepted: 2692

    Description

    Encoding schemes are often used in situations requiring encryption or information storage/transmission economy. Here, we develop a simple encoding scheme that encodes particular types of words with five or fewer (lower case) letters as integers. 

    Consider the English alphabet {a,b,c,...,z}. Using this alphabet, a set of valid words are to be formed that are in a strict lexicographic order. In this set of valid words, the successive letters of a word are in a strictly ascending order; that is, later letters in a valid word are always after previous letters with respect to their positions in the alphabet list {a,b,c,...,z}. For example, 

    abc aep gwz 

    are all valid three-letter words, whereas 

    aab are cat 

    are not. 

    For each valid word associate an integer which gives the position of the word in the alphabetized list of words. That is: 

    a -> 1
    b -> 2
    .
    .
    z -> 26
    ab -> 27
    ac -> 28
    .
    .
    az -> 51
    bc -> 52
    .
    .
    vwxyz -> 83681

    Your program is to read a series of input lines. Each input line will have a single word on it, that will be from one to five letters long. For each word read, if the word is invalid give the number 0. If the word read is valid, give the word's position index in the above alphabetical list. 

    Input

    The input consists of a series of single words, one per line. The words are at least one letter long and no more that five letters. Only the lower case alphabetic {a,b,...,z} characters will be used as input. The first letter of a word will appear as the first character on an input line. 

    The input will be terminated by end-of-file.

    Output

    The output is a single integer, greater than or equal to zero (0) and less than or equal 83681. The first digit of an output value should be the first character on a line. There is one line of output for each input line.

    Sample Input

    z
    a
    cat
    vwxyz

    Sample Output

    26
    1
    0
    83681
    和1850一样的题。。。
    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<algorithm>
    
    using namespace std;
    
    const int maxn=1000100;
    const int INF=(1<<28);
    
    string str;
    int code;
    int C[30][30];
    
    void creat_C()
    {
        memset(C,0,sizeof(C));
        for(int i=0;i<=28;i++){
            for(int j=0;j<=i;j++){
                if(j==0||j==i) C[i][j]=1;
                else C[i][j]=C[i-1][j-1]+C[i-1][j];
            }
        }
    }
    
    int main()
    {
        creat_C();
        while(cin>>str){
            bool flag=1;
            for(int i=0;i<str.length()-1;i++){
                if(str[i]>=str[i+1]){
                    cout<<0<<endl;
                    flag=0;
                }
            }
            if(!flag) continue;
            code=0;
            int len=str.length();
            for(int i=1;i<=len-1;i++){
                code+=C[26][i];
            }
            for(int i=0;i<len;i++){
                char ch=i?str[i-1]+1:'a';//ch至少要比前一个大
                for(;ch<str[i];ch++){
                    code+=C['z'-ch][len-i-1];
                }
            }
            cout<<code+1<<endl;
        }
        return 0;
    }
    View Code
    没有AC不了的题,只有不努力的ACMER!
  • 相关阅读:
    vue2.5.2 在ie11打开空白的解决方法
    小程序自定义组件中observer函数的应用
    小程序将一个完整项目导入,报错ENOENT: no such file or directory(game.json)
    企业微信应用开发前准备
    jquery转盘抽奖游戏
    小程序路由跳转携带参数方法(直接跳转、事件委托跳转)
    小程序定义并使用模板template
    小程序真机预览,提示“音乐文件错误,播放失败”
    Java反编译
    DataX
  • 原文地址:https://www.cnblogs.com/--560/p/4361323.html
Copyright © 2011-2022 走看看