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. CSS---input标签注意

    总结一下,在给input标签写CSS时需要注意的有以下几点: 一.不要给属性为text的input标签设置高度,这样无法让IE浏览器下输入框中的文字垂直居中显示.尽管你后来想要通过设置padding属 ...

  2. javascript - 工作笔记 (事件绑定)

    背景: 目前所做的项目,只能使用的是原生的javascript.对于javascript的事件绑定想必大家都懂得语法: 1,在标签中使用属性调用方法:<div onclick="AAA ...

  3. JSON 解析器。JSON.stringify和JSON.parse

    以前用的是JavaScript  的eval. 现在JSON 提供了JSON.stringify和JSON.parse两个函数. JSON.parse用于从一个字符串中解析出json对象. JSON. ...

  4. php使用check box

    if (isset($_POST['submit'])) { foreach ($_POST['todelete'] as $delete_id) { //这里是循环遍历这个数组 todelete 每 ...

  5. Ultra-QuickSort(归并排序)

    Ultra-QuickSort Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 49267   Accepted: 18035 ...

  6. c# 针对不同数据库进行参数化查询

    使用参数化 DbCommand 的一个缺点是需要参数的代码将仅适用于支持相同语法的提供程序.OLEDB.SqlClient 和 Oracle 提供程序全部使用不同的语法.例如,用于命名和指定参数的 S ...

  7. 如何在MFC中操作资源句柄

    如何获取动态库中对话框相关资源,避免因资源问题报错? AfxGetResourceHandle用于获取当前资源模块句柄AfxSetResourceHandle则用于设置程序目前要使用的资源模块句柄. ...

  8. Nutch安装的几个网址

    RunNutchInEclipse - Nutch Wiki   http://wiki.apache.org/nutch/RunNutchInEclipse Index of /apache/nut ...

  9. android UI-EditText的长度监听慎用TextWatcher

    在用户昵称的输入时,限定8个字符,本意是在输入超过8个时候,页面toast一个提示,就是下面的TextWatcher的监听,在afterTextChanged中处理. 原bug:huawei MT2- ...

  10. Hive常用操作之数据导入导出

    一.Hive数据导入导出 1.hive数据导出 很多时候,我们在hive中执行select语句,希望将最终的结果保存到本地文件或者保存到hdfs系统中或者保存到一个新的表中,hive提供了方便的关键词 ...