组合数学poj 1496 1850 同样的代码过两题
Description 1942
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 1496
Description
Consider the English alphabet {a,b,c,...,z}. Using this alphabet, a set of valid words are to be formed that are in a strict lexicographic order. In this set of valid words, the successive letters of a word are in a strictly ascending order; that is, later letters in a valid word are always after previous letters with respect to their positions in the alphabet list {a,b,c,...,z}. For example,
abc aep gwz
are all valid three-letter words, whereas
aab are cat
are not.
For each valid word associate an integer which gives the position of the word in the alphabetized list of words. That is:
a -> 1
b -> 2
.
.
z -> 26
ab -> 27
ac -> 28
.
.
az -> 51
bc -> 52
.
.
vwxyz -> 83681
Your program is to read a series of input lines. Each input line will have a single word on it, that will be from one to five letters long. For each word read, if the word is invalid give the number 0. If the word read is valid, give the word's position index in the above alphabetical list.
Input
The input will be terminated by end-of-file.
Output
Sample Input
z
a
cat
vwxyz
Sample Output
26
1
0
83681
#include"iostream"
#include"cstdio"
#include"cstring"
using namespace std;
const int ms=;
int c[ms+][ms+];
int main()
{
int i,j;
//bool flag;
for(i=;i<=ms;i++)
{
c[i][]=c[i][i]=;
}
for(i=;i<=ms;i++)
for(j=;j<i;j++)
c[i][j]=c[i-][j]+c[i-][j-];
char str[ms];
while(scanf("%s",str)!=EOF)
{
bool flag=false;
int len=strlen(str);
for(i=;i<len;i++)
if(str[i]<=str[i-])
{
flag=true;
break;
}
if(flag)
{
printf("0\n");
continue;
}
int ans=;
i=;
while(i<len)
ans+=c[][i++];
i=-;
int k=;
while(k<len)
{
i++;
if(k==len-)
{
//if(i+'a'<=str[k])
while(i+'a'<=str[k])
{
ans++;
i++;
}
break;
}
while(i+'a'<str[k])
{
//if(i+'a'<str[k])
//{
ans+=c[-i-][len--k];
i++;
continue; }
k++;
}
printf("%d\n",ans);
}
return ;
}
组合数学poj 1496 1850 同样的代码过两题的更多相关文章
- POJ 1496 POJ 1850 组合计数
Code Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8256 Accepted: 3906 Description Tran ...
- ORA-01810: 格式代码出现两次
今天在修改SQL语句的时候遇到这个小问题,提示的还是比较明显的,当然解决之道我是从百度上摘取的! 错误语句段:AND V.UPLOAD_DATE <=TO_DATE ('2013-11-11 2 ...
- ORA-01810格式代码出现两次 的解决方案
今早做一个查询页面时,需要查询两个时间区间的跨度,使用TO_DATE函数,一开始写成了Sql代码 TO_DATE('2014-08-04 00:00:00','YYYY-MM-DD HH:mm:ss' ...
- ORA-01810:格式代码出现两次 解决方法
在写一个sql插入数据库的时候 to_date('20140509131034','yyyyMMddHHmmss') 报ORA-01810:格式代码出现两次 原因是java中的年月日和oracle中的 ...
- 格式代码出现两次oracle
报ORA-01810:格式代码出现两次 原因是Java中的年月日和Oracle中的年月日表示形式不一样 oracle用MI来代表分钟,而不是java中的mm
- springboot项目启动成功后执行一段代码的两种方式
springboot项目启动成功后执行一段代码的两种方式 实现ApplicationRunner接口 package com.lnjecit.lifecycle; import org.springf ...
- angularjs 代码结构两种写法
1.当路由中不写controller的时候,controller写在对应的html表单中 2.若要写在路由中,如下 3.转到相应的路由(页面) 1.采用location服务 2.采用 transiti ...
- poj 1850/poj 1496
http://poj.org/problem?id=1850 -----------------http://poj.org/problem?id=1496 两题解法类似..本题为组合数学的题,要求所 ...
- POJ 1496 Word Index
组合数学....和上一题是一样的.... Word Index Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4303 Acce ...
随机推荐
- 《GettingThingsDone》--GTD学习笔记(二)-GTD实践指导
一.准备阶段的建议: 高级的工作管理方法就是学会一套系统并付诸实施,直到将这套系统和方法融入你的工作和生活中. 通过行动使自己感觉良好,要比通过使自己感觉良好而进入一种较佳的行动状态容易的多. 当你在 ...
- 发布 asp.net网站 到本地IIS
http://blog.csdn.net/jiben2qingshan/article/details/9249139 概述 网站是由一个个页面组成的,是万维网具体的变现形式,关于万维网,网页的方面的 ...
- EasyMock
使用 EasyMock 更轻松地进行测试 窥探EasyMock(1)基础使用篇 窥探EasyMock(2)进阶使用篇
- [VS2012]无法新建或者编译已有的项目
今天启动VS2012时,发现提示插件错误,然后打开以前的网站时,发现报错如下: ContractNameMicrosoft.VisualStudio.Utilities.IContentTypereg ...
- HDU 4864 Task (贪心)
Task 题目链接: http://acm.hust.edu.cn/vjudge/contest/121336#problem/B Description Today the company has ...
- Linux下python升级步骤
先安装openssl,openssl-devel yum install openssl yum install openssl-devel 1切换到指定的目录下: cd /usr/local 2下载 ...
- CodeForces 548A Mike and Fax (回文,水题)
题意:给定一个字符串,问是不是恰好存在 k 个字符串是回文串,并且一样长. 析:没什么好说的,每次截取n/k个,判断是不是回文就好. 代码如下: #include<bits/stdc++.h&g ...
- 【BJG吐槽汇】第一期 - 警惕亚马逊莫名自动扣款!千万不要进了它的坑!
BJG吐槽汇:一直以来我都觉得其实生活中工作中会有各种各样奇葩的事或者奇葩的人可以去吐槽,那么BeJavaGod本身聊得就是关于JavaWeb技术,互联网技术,互联网产品等,那么今天起咱们开了这么一档 ...
- mime type 概要介绍
内容类型 内容类型(Content-Type),这个头部领域用于指定消息的类型.一般以下面的形式出现. Content-Type: [type]/[subtype]; parameter type t ...
- ASP导出Word带页眉页脚,中文不乱码
关键代码: <% Response.Clear() Response.CodePage= Response.Charset="UTF-8" Response.ContentT ...