poj1850 Code
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 10059 | Accepted: 4816 |
Description
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 word is maximum 10 letters length
• The English alphabet has 26 characters.
Output
Sample Input
bf
Sample Output
55
Source
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int c[][], len, ans;
char s[]; int main()
{
c[][] = ;
for (int i = ; i <= ; i++)
{
c[i][] = ;
for (int j = ; j <= ; j++)
c[i][j] = c[i - ][j - ] + c[i - ][j];
} while (~scanf("%s", s + ))
{
ans = ;
bool can = true;
len = strlen(s + );
for (int i = ; i <= len; i++)
if (s[i] <= s[i - ])
{
can = false;
break;
}
if (!can)
{
printf("0\n");
continue;
}
for (int i = ; i < len; i++)
ans += c[][i];
for (int i = ; i <= len; i++)
{
int ch = s[i] - 'a', ch2;
if (i == )
ch2 = ;
else
ch2 = s[i - ] - 'a' + ;
if (i == len)
ans += ch - ch2;
else
{
while (ch2 < ch)
{
ans += c[ - ch2 - ][len - i];
ch2++;
}
}
}
ans++;
printf("%d\n", ans);
} return ;
}
poj1850 Code的更多相关文章
- poj1496 Word Index / poj1850 Code(组合数学)
poj1850 Code 题意:输出若干个给定的字符串($length<=10$)在字典序中的位置,字符串中的字母必须严格递增. 读取到非法字符串时,输出“0”,终止程序.(poj1496:继续 ...
- POJ1850——Code(组合数学)
Code DescriptionTransmitting and memorizing information is a task that requires different coding sys ...
- poj1850 Code【组合数学】By cellur925
题意: * 按照字典序的顺序从小写字母 a 开始按顺序给出序列 (序列中都为升序字符串)* a - 1* b - 2* ...* z - 26* ab - 27* ...* az - 51* bc - ...
- POJ1850 Code(组合+康托展开)
题目问一个合法字符串的字典序是第几个,合法的字符串是指里面的字符严格递增. 先判断合不合法,然后用类似康托展开的过程去求.大概过程就是用组合数算出某长度某前缀有几个,累加起来. 真难一遍写对.. #i ...
- 【poj1850】 Code 数位dp+记忆化搜索
题目大意:给你一个字符串,问你这个字符串的rank,如果这个字符串不合法,请直接输出0.(一个合法的字符串是对于∀i,有c[i]<c[i+1]) 字符串s的rank的计算方式:以字符串长度作为第 ...
- Visual Studio Code 代理设置
Visual Studio Code (简称 VS Code)是由微软研发的一款免费.开源的跨平台文本(代码)编辑器,在十多年的编程经历中,我使用过非常多的的代码编辑器(包括 IDE),例如 Fron ...
- 我们是怎么做Code Review的
前几天看了<Code Review 程序员的寄望与哀伤>,想到我们团队开展Code Review也有2年了,结果还算比较满意,有些经验应该可以和大家一起分享.探讨.我们为什么要推行Code ...
- Code Review 程序员的寄望与哀伤
一个程序员,他写完了代码,在测试环境通过了测试,然后他把它发布到了线上生产环境,但很快就发现在生产环境上出了问题,有潜在的 bug. 事后分析,是生产环境的一些微妙差异,使得这种 bug 场景在线下测 ...
- 从Script到Code Blocks、Code Behind到MVC、MVP、MVVM
刚过去的周五(3-14)例行地主持了技术会议,主题正好是<UI层的设计模式——从Script.Code Behind到MVC.MVP.MVVM>,是前一天晚上才定的,中午花了半小时准备了下 ...
随机推荐
- EasyUI validatebox 自定义ajax验证用户名是否已存在
<td><input type="text" id="userName" name="userName" class=&q ...
- 【python 3.6】调用另一个文件的类的方法
文件1:test12.py 文件2:test13.py 文件1 如下: #!/usr/bin/python # -*- coding: utf-8 -*- ''' ''' class abcd(obj ...
- Spark Streaming的使用——转载
转载自 Spark Streaming 使用
- [leetcode-914-X of a Kind in a Deck of Cards]
In a deck of cards, each card has an integer written on it. Return true if and only if you can choos ...
- 【每日scrum】NO.9
(1)这是我们冲刺的最后一天,晚上我们的团队进行了收尾工作:第一阶段的任务基本完成,软件主要实现了校园景点照片以及对应的介绍,查询最短路径,查询涉及相关景点的查询,查询全部路径,基本界面的设计,导航功 ...
- hdu1010--Tempter of the Bone(迷宫)
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1010 Tempter of the Bone Time Limit: 2000/1000 MS (Jav ...
- 字典树---2001 POJ Shortest Prefixes(找最短前缀)
做的第一道字典树的题,算比较水的: -->>>:传送门 代码: #include <stdio.h> #include<stdlib.h> #define M ...
- CentOS6.5 重启网络报错:Bringing up interface eth0: Error: Connection activation failed: Device not managed by NetworkManager or unavailable
CentOS6.5 重启网络报错: Bringing up interface eth0: Error: Connection activation failed: Device not manage ...
- 【Linux 命令】- more和less
more命令 more功能类似 cat ,cat命令是整个文件的内容从上到下显示在屏幕上. more会以一页一页的显示方便使用者逐页阅读,而最基本的指令就是按空白键(space)就往下一页显示,按 b ...
- 【Linux】- 简明Vim练习攻略
vim的学习曲线相当的大(参看各种文本编辑器的学习曲线),所以,如果你一开始看到的是一大堆VIM的命令分类,你一定会对这个编辑器失去兴趣的.下面的文章翻译自<Learn Vim Progress ...