Code
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 7913   Accepted: 3709

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.

Input

The only line contains a word. There are some constraints: 
• 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
//首先观察规律
1+1.....1 
+
(25+...+1)
+
((24+..+1) + (23+..+1)+..+1)
+
[(24+..+1) + (23+..+1)+..+1)]+[(23+..+1)+..+1)]+...[1]
+....
//所以我维护了一个num[10][27]的数组
for(i=26;i>n;i--)
{
sum+=num[n-1][i];
num[n][i]=sum;
}
num[i]中的所有数字相加 就是 代表 第i层完成之后的编号:
举例:bcd
这说明 前面的a开头的肯定完整了 所以这时候就是需要num[0]+num[1]所有元素的和 +num[2][1](代表三个字符的以a开头的所有数量) =bcd=26+325+300=651 然后加上bcd自己 就是652 这只是第一层上面的字母对于a偏移了 ,如果 第n层对第n-1层偏移的话 如
aef e对b偏移了 那么这个怎么算了
我们可以忽略a 因为这里a对其不产生影响,唯一的影响是对e的起始的偏移位置的影响
所以我们可以用num[2][b-'a'+数组中起始有值的位置]+num[2][c-'a'+数组中起始有值的为位置]+....
/*
26 +
(25+...+1)
(25*24/2 +24*23/2 +...) +
( (24*23/2 +...) +(23*22/2+.....) )
*/
#include<stdio.h>
#include<string.h>
__int64 num[][];
void dfs(__int64 n)
{
__int64 i;
if(n>) return ; __int64 sum=;
for(i=;i>n;i--)
{
sum+=num[n-][i];
num[n][i]=sum;
}
dfs(n+);
}
int main(void)
{
__int64 i,j;
char str[];
for(i=;i<;i++) num[][i]=;
dfs();
while(scanf("%s",&str[])!=EOF)
{
__int64 len=strlen(str)-;
__int64 tol=;
//除掉不满足情况的
for(i=;i<=len;i++)
{
if(str[i]<=str[i-]){ printf("0\n");
return ;}
} for(i=;i<len-;i++)//先算总层
{
for(j=;j>=i;j--)
{ tol+=num[i][j];
}
}
str[]='a'-;//起始的时候处理一下
for(j=len;j>;j--){
for(i=;i<str[len-j+]-(str[len-j]+);i++)
{
tol+=num[j-][j+i+(str[len-j]+-'a')];
}
} printf("%I64d\n",tol);
}
return ;
}

ps:woshi1993

POJ 1850 Code(找规律)的更多相关文章

  1. URAL 1780 G - Gray Code 找规律

    G - Gray CodeTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...

  2. POJ 1850 Code(组合数)

    http://poj.org/problem?id=1850 题意 :给定字符串,系统是用字符串组成的,字符串是按字典序排的.编码系统有三条规则,1这些的单词的长度是由小到大的,2相同长度的按字母在字 ...

  3. poj 1850 code(组合数学)

    题目:http://poj.org/problem?id=1850 题意:按给定的规则给字母编号. 一个很简单的题目,但是却做了好久.................................. ...

  4. POJ 1850 Code

    组合数学.... Code Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7202 Accepted: 3361 Descrip ...

  5. POJ 1850 Code 字符串 难度:1

    题意: 1 如果是严格升序的字母字符串,那么可以输出非0解码,否则不能译码输出0 2 字符串解码 遵循递增原则,其值为 到现在为止的所有按字母序小于该字符串的数量 + 1; #include < ...

  6. 暑假集训单切赛第一场 POJ 2309 BST(找规律的题)

    题意:给出一棵二分搜索树,再给一个节点编号n,求以这个节点为根节点的子树叶子节点的最大值与最小值. 首先求n所在的层数,他的层数就是他的因子中2的个数(规律). n的左右各有num=2^i-1个数.最 ...

  7. POJ - 1850 Code(组合数学)

    https://vjudge.net/problem/POJ-1850 题意 输出某字符串在字典中的位置.字符串不合规则时输出0. 分析 首先判断字符串合法性,也就是判断是不是升序排列的.如果符合,以 ...

  8. poj:1850 Code(组合数学?数位dp!)

    题目大意:字符的字典序依次递增才是合法的字符串,将字符串依次标号如:a-1 b-2 ... z-26 ab-27 bc-52. 为什么题解都是组合数学的...我觉得数位dp很好写啊(逃 f[pos][ ...

  9. POJ 1740 A New Stone Game 又是博弈论配对找规律orz 博弈论 规律

    http://poj.org/problem?id=1740 这个博弈一眼看上去很厉害很高大上让人情不自禁觉得自己不会写,结果又是找规律…… 博弈一般后手胜都比较麻烦,但是主要就是找和先手的对应关系, ...

随机推荐

  1. J2SE知识点摘记(十三)

    1.        字节流 InputStream(输入字节流)是一个定义了java流式字节流输入模式的抽象类.该类的所有方法在出错时都会引发一个IOExcepiton异常. Void close() ...

  2. PADS无模命令总结

    1.PADS2007无模命令与快捷键 <x.y>表示坐标.<s>表示文体.<n>表示数字. 1.[C]显示平面的焊盘和热焊盘(Thermal). 2.[D]显示当前 ...

  3. nautilus-open-terminal右键随处打开终端

    Nautilus-Open-Terminal : 可随处打开终端的 Nautilus 插件 nautilus-open-terminal-0.17-4.el6.x86_64 是一个让你随处都可以打开终 ...

  4. 从ACM中删除一个已经创建的Library

    从ACM中删除一个已经创建的Library,无法通过界面操作,须要手工从DB中删除.须要删除的表记录有: RECENTUPDATE 找到字段Name等于该libraryName的那条记录删除掉 del ...

  5. HDU 3046 Pleasant sheep and big big wolf(最小割)

    HDU 3046 Pleasant sheep and big big wolf 题目链接 题意:一个n * m平面上,1是羊.2是狼,问最少要多少围墙才干把狼所有围住,每有到达羊的路径 思路:有羊和 ...

  6. sql server dateadd()

    定义和用法 DATEADD() 函数在日期中添加或减去指定的时间间隔. 语法 DATEADD(datepart,number,date) date 参数是合法的日期表达式.number 是您希望添加的 ...

  7. 简单的CSS网页布局--三列布局

    三列布局其实不难,不过要用到position:absolute这个属性,因为这个属性是基于浏览器而言,左右部分各放在左右侧,空出中间一列来实现三列布局. (一)三列布局自适应 <!DOCTYPE ...

  8. JavaScript之模仿块级作用域

    简介:在JavaScript中没有块级作用域的概念.这意味这在块语句中定义的变量,实际上在包含函数中而非语句中创建的.证明代码如下: function outputNumbers(count){ fo ...

  9. select2插件常用方法汇总

    1.获取下拉框的value和text <input type="hidden" name="xa" id="xa" data-plac ...

  10. Oracle分析函数之开窗子句-即WINDOWING子句

    Oracle的分析函数,对我们进行统计有很大的帮助,可以避免一些子查询等操作,在统计中,我们对开窗函数的接触较少,下面主要介绍下开窗函数的使用; http://www.itpub.net/thread ...