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>,是前一天晚上才定的,中午花了半小时准备了下 ...
随机推荐
- 学习GIT 你只要这一篇(转)
http://blog.csdn.net/afei__/article/details/51476529 安装之后第一步 安装 Git 之后,你要做的第一件事情就是去配置你的名字和邮箱,因为每一次提交 ...
- BZOJ 3489 A simple rmq problem 可持久化KDtree/二维线段树
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=3489 题意概述: 给出一个序列,每次询问一个序列区间中仅出现了一次的数字最大是多少,如果 ...
- scrum立会报告+燃尽图(第三周第六次)
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2286 项目地址:https://coding.net/u/wuyy694 ...
- Java:有关try、catch和finally的学习(供自己参考)
Java:有关try.catch和finally的学习 在看到书本的时候对finally的介绍是:不论是否在try块中产生异常,都会执行finally.当时对这句话的理解不够深,误以为在try...c ...
- 《C》数组
数组 数组方法: var arr = [1, 2, 3]; arr.push(4)://arr='[1, 2, 3, 4]' 向末尾添加一个或者多个元素 arr.pop()://删除末位元素 var ...
- 福大软工1816 - 404 Note Found选题报告
目录 NABCD分析引用 N(Need,需求): A(Approach,做法): B(Benefit,好处): C(Competitors,竞争): D(Delivery,交付): 初期 中期 个人贡 ...
- Codeforces Beta Round #8 C. Looking for Order 状压dp
题目链接: http://codeforces.com/problemset/problem/8/C C. Looking for Order time limit per test:4 second ...
- HDU 5211 Mutiple 水题
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5211 题解: 1.筛法: #include<iostream> #include< ...
- java下执行mongodb
1.1连单台mongodb Mongo mg = newMongo();//默认连本机127.0.0.1 端口为27017 Mongo mg = newMongo(ip);//可以指定ip 端口默认 ...
- 使用windows live writer发表的博客
试插入代码 #include <iostream.h> using namespace std; int main() { cout<<"hello world&qu ...