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. [LeetCode][Python]String to Integer (atoi)

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

  2. Android 模拟系统事件(三)

    简介 Android系统是基于Linux内核的,而Linux内核继承和兼容了丰富的Unix系统进程间通信(IPC)机制.Binder其实也不是Android提出来的一套新的进程间通信机制,它是基于Op ...

  3. poj2486 Apple Tree (树形dp)

    题意:有一颗苹果树,树上的u节点上有num[u]个苹果,树根为1号节点,囧king从根开始走,没走到一个节点就把接点上的苹果吃光,问囧king在不超过k步的情况下最多吃多少个苹果. 解题思路:处理出两 ...

  4. CXF 的IP拦截

    非常久没有写技术文档了,今天 记录下Webserver的Ip限制吧 需求是:webserver接口能在内网訪问,可是測试平台的webserver要能够在外网訪问,这样就有了一点差别, 这个实现的比較简 ...

  5. POJ 3692 Kindergarten (二分图 最大团)

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5660   Accepted: 2756 Desc ...

  6. IHttpModule与IHttpHandler的区别整理

    IHttpModule与IHttpHandler的区别整理1.先后次序.先IHttpModule,后IHttpHandler. 注:Module要看你响应了哪个事件,一些事件是在Handler之前运行 ...

  7. ORACLE 查找字段在哪些表里存在

    查找不是主键的字段在哪些表里存在: select owner, table_namefrom dba_tab_columnswhere lower(column_name)='firstname'; ...

  8. 基于Jquery的Ajax分页,只有上一页和下一页

    最近项目中用到ajax分页 在网上找到一个非常好用的分页插件jquery-pagination-ajax,以下是链接 http://www.zhangxinxu.com/wordpress/2010/ ...

  9. hadoop 配置文件注意问题

    一定要配置成hostname形式: 如伪分布:配成localhost:9000 完全分布:配成big1:9000

  10. Oracle聚合求和和聚合求积(顺便解决BOM展开的问题)

    本文参考网址:http://www.itpub.net/thread-1020772-1-1.html 我们在日常的工作中,经常遇到了针对某一列的值,进行求和,求平均值,在一些特殊的业务场景下,我们需 ...