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. JSP中的Attribute和InitParameter

    属性:Attribute类型:应用/上下文,请求,会话(ServletContext,HttpServletRequest/ServletRequest,HttpSession)设置方法:setAtt ...

  2. Android Studio设置自动编译工程

  3. Microsoft Azure 在北美 TechEd 大会上发布令人振奋的更新,帮助客户开始使用云服务

    云计算因其速度.规模和成本节省等优势而备受众多企业青睐.但企业需帮助,才能以安全可靠的方式使用云,同时还要利用企业的现有投资, 才能实现这些优势.因此,在TechEd 大会上,我们推出了一些新的服务, ...

  4. poj1657---chessboard

    对棋盘横纵坐标的解读 str1="f3" str2="e9" x=abs(str1[0]-str2[0]) y=abs(str1[1]-str1[1]) 如果x ...

  5. [LeetCode][Python]ZigZag Conversion

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/zigzag- ...

  6. Openstack 的 RPC使用。

    大家都已经很熟悉了RPC了. 比如说nfs就是采用的RPC通信. 尤其SUN RPC 已经成为了C语言开发的经典一种进程间调用机制. openstack 的RPC 机制, 是基于AMQP 活着其他高级 ...

  7. location的用法

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. 高德地图API

    这周计划: 周一 早上 (高德地图API) 中午写(IFE PART ONE) 下午(高德地图API) 下班(IFE PART ONE)

  9. zoj2729 Sum Up(模拟)

    Sum Up Time Limit: 2 Seconds      Memory Limit: 65536 KB Vivid has stored a piece of private informa ...

  10. 【MongoDB数据库】MongoDB 命令入门初探

    MongoDB是一款NoSql数据库,使用了"面向集合"(Collection-Oriented)原理,意思是数据被分组存储在数据集中,被称为一个集合(Collection).每一 ...