| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1622 人关注过本帖
标题:ACM类的题目,大神告诉速度来帮帮我。
只看楼主 加入收藏
liyue6822532
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2016-2-28
结帖率:57.14%
收藏
已结贴  问题点数:20 回复次数:7 
ACM类的题目,大神告诉速度来帮帮我。
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.
输入

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.
输出

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.
样例输入

z
a
cat
vwxyz

样例输出

26
1
0
83681
搜索更多相关主题的帖子: particular English develop letters storage 
2016-03-20 14:18
luckhide
Rank: 5Rank: 5
来 自:青岛
等 级:职业侠客
帖 子:51
专家分:338
注 册:2016-3-19
收藏
得分:0 
我帮你顶起来!应该不是太难的,肯定有大神帮你解决。
2016-03-21 15:15
azzbcc
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江西财经大学
等 级:贵宾
威 望:81
帖 子:3293
专家分:12919
注 册:2012-11-4
收藏
得分:0 
这个是排列组合的题

一共 C(26,1) + C(26,2) + ... + C(26, 5) = 83681

以 ace 为例

等于 X + XX + abX + acd + ace = C(26, 1) + C(26, 2) + C(24, 1) + 1 + 1 = 377



[fly]存在即是合理[/fly]
2016-03-21 17:54
luckhide
Rank: 5Rank: 5
来 自:青岛
等 级:职业侠客
帖 子:51
专家分:338
注 册:2016-3-19
收藏
得分:0 
回复 3楼 azzbcc
嗯,大方向上的计数正是排列组合的总数和,关键还是组合内的规律。如26组3,其起始abc的序号=c(26,1)+c(26,2)+1,可是bkm的序号和abc的序号又是什么规律呢?应该也可以总结出一个算式的。
2016-03-22 09:04
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9025
专家分:54030
注 册:2011-1-18
收藏
得分:20 
程序代码:
#include <stdio.h>

unsigned foo( const char* s )
{
    size_t n;
    for( n=1; s[n]!=0 && s[n]>s[n-1]; ++n );
    if( s[n] != 0 )
        return 0;

    const unsigned base[] = { 1, 27, 352, 2952, 17902 };
    unsigned sum = base[n-1];
    for( const char* p=s; *p; ++p, --n )
    {
        unsigned x=1, y=1, z=1;
        for( unsigned i=1; i<=n; ++i )
        {
            x *= 'z'+2-i - (p==s?'a':p[-1]+1);
            y *= 'z'+2-i - (*p);
            z *= i;
        }
        sum += (x-y)/z;
    }
    return sum;
}

int main( void )
{
    for( char s[6]; scanf("%s",s)==1; )
        printf( "%u\n", foo(s) );

    return 0;
}
2016-03-22 10:46
luckhide
Rank: 5Rank: 5
来 自:青岛
等 级:职业侠客
帖 子:51
专家分:338
注 册:2016-3-19
收藏
得分:0 
回复 5楼 rjsp
大师!
2016-03-22 12:05
liyue6822532
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2016-2-28
收藏
得分:0 
厉害 不过看不懂。。。
2016-03-23 19:31
luckhide
Rank: 5Rank: 5
来 自:青岛
等 级:职业侠客
帖 子:51
专家分:338
注 册:2016-3-19
收藏
得分:0 
回复 7楼 liyue682253
大哥,我帮你顶的!我没给答案是要人关注你的问题,并不代表我不能给你正确答案,你仓促结帖,甚至不懂,达不到你需求啊。
2016-03-23 19:41
快速回复:ACM类的题目,大神告诉速度来帮帮我。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017877 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved