POJ 1580 Code
来源:互联网 发布:科比三连冠时期数据 编辑:程序博客网 时间:2024/05/16 06:17
Code
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 6453 Accepted: 3026
Description
Transmitting and memorizing information is a task that requires different coding systems for the best use of the available space. A well known system is that one where a number is associated to a character sequence. It is considered that the words are made only of small characters of the English alphabet a,b,c, ..., z (26 characters). From all these words we consider only those whose letters are in lexigraphical order (each character is smaller than the next character).
The coding system works like this:
• The words are arranged in the increasing order of their length.
• The words with the same length are arranged in lexicographical order (the order from the dictionary).
• We codify these words by their numbering, starting with a, as follows:
a - 1
b - 2
...
z - 26
ab - 27
...
az - 51
bc - 52
...
vwxyz - 83681
...
Specify for a given word if it can be codified according to this coding system. For the affirmative case specify its code.
The coding system works like this:
• The words are arranged in the increasing order of their length.
• The words with the same length are arranged in lexicographical order (the order from the dictionary).
• We codify these words by their numbering, starting with a, as follows:
a - 1
b - 2
...
z - 26
ab - 27
...
az - 51
bc - 52
...
vwxyz - 83681
...
Specify for a given word if it can be codified according to this coding system. For the affirmative case specify its code.
Input
The only line contains a word. There are some constraints:
• The word is maximum 10 letters length
• The English alphabet has 26 characters.
• The word is maximum 10 letters length
• The English alphabet has 26 characters.
Output
The output will contain the code of the given word, or 0 if the word can not be codified.
Sample Input
bf
Sample Output
55
Source
Romania OI 2002
这题我一开始因为一个字符写错了,不断的wa,我都无奈了,最后才注意到一个字符的错误,这个题最好用杨辉三角求组合数,否者要考虑精度问题。 注释掉的是我用的要考虑精度的算法。 这种算法相对来说比较耗时,每次要求组合数的时候都要重新进行,不如 杨辉三角这接打表 省时
#include <stdio.h>#include <string.h>#include <math.h>char s1[20];int zuhe[27][27];int main(){ long long int f(int m,int n); void get_zuhe(); int i,j,n,m,t,l; long long int s; get_zuhe(); while(scanf("%s",s1)!=EOF) { l=strlen(s1); for(i=1; i<=l-1; i++) { if(s1[i]<=s1[i-1]) { printf("0\n"); break; } } if(i!=l) { continue; } if(l==1) { printf("%d\n",s1[0]-'a'+1); } else { s=0; for(i=1; i<=l-1; i++) { s+=f(i,26); } for(i=0; i<=l-1; i++) { if(i==0) { t=s1[i]-'a'; } else { t=s1[i]-s1[i-1]-1; } if(i!=l-1) { for(j=1; j<=t; j++) { if(i==0) { s+=f(l-1-i,26-j); } else { s+=f(l-1-i,'z'-(s1[i-1]+j)); } } } } s+=(s1[l-1]-s1[l-2]); printf("%lld\n",s); } } return 0;}void get_zuhe(){ int i,j; memset(zuhe,0,sizeof(zuhe)); for(i=0; i<=26; i++) { for(j=0; j<=i; j++) { if(!j||i==j)zuhe[i][j]=1; else zuhe[i][j]=zuhe[i-1][j-1]+zuhe[i-1][j]; } }}long long int f(int m,int n){ long long int s; s=zuhe[n][m]; return s;}/*long long int f(int m,int n){ int i,j; long long int res; double s=1.0; for(i=n,j=m;i>=n-m+1;i--,j--) { s=s*(double)i/(double)j; } res=(long long int)(s+0.01); return res;} */
- POJ 1580 Code
- Code POJ
- Code POJ
- poj 1850 Code
- poj 1850 Code
- poj 1850 code
- poj 1850 Code
- poj 1850 Code
- POJ 1042 Source Code
- poj 1850 Code
- poj 1850 Code
- poj 2015 Permutation Code
- POJ 1850 Code
- POJ 1850 Code
- poj 1850 Code
- POJ 1850 Code
- POJ 1896 Code Formatting
- POJ 2015 Permutation Code
- C++编译不通过问题排查
- Git repo 常用命令
- 四巨头GoF的《设计模式》中23种设计模式的UML图 - 3 of 4
- vcl消息
- IBM “New Power”五大新计划
- POJ 1580 Code
- 毕业设计(十八)---发表文章(4)之- 发表文章流程 表单,处理代码
- oracle exec 和 call 区别
- Python 初体验 之 面向对象
- HEVC学习(三十五) —— 去方块滤波之六
- freeswitch 解决方案之电话会议 conference
- Unity3d脚本中文支持
- cocos2d-x 2.0版本 自适应屏幕分辨率
- cocos2dx学习笔记(转)