组合数学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 ...
随机推荐
- Could not bind factory to JNDI
将hibernate.cfg.xml中 <session-factory name="SessionFactory">的name属性去掉即可
- Gym 100507I Traffic Jam in Flower Town (模拟)
Traffic Jam in Flower Town 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/I Description ...
- Javascript高级篇-面向对象的特性
一.创建对象 1.1初始化器 var any={ name:"some", age:10, action:function(){ alert(this.name+":&q ...
- Objc基础学习记录1
1.'-'系在实例方法前头 2.'+'类方法class method 相反; 3.void表示没有返回值; 4.&x 和c语言一样,代表的是x的在内存上的地址; 5.*y指向内存存储空间内的数 ...
- Unity中2D和UGUI图集的理解与使用
图集 什么是图集? 在使用3D技术开发2D游戏或制作UI时(即使用GPU绘制),都会使用到图集,而使用CPU渲染的2D游戏和UI则不存在图集这个概念(比如Flash的原生显示列表),那么什么是图集呢? ...
- 山东理工大学ACM平台题答案关于C语言 1580 闰年
闰年 Time Limit: 1000ms Memory limit: 32768K 有疑问?点这里^_^ 题目描述 时间过得真快啊,又要过年了,同时,我们的人生也增长了一年的阅历,又成熟了一些 ...
- UML学习(二)-----类图
UML学习(二)-----类图 http://www.cnblogs.com/silent2012/archive/2011/09/07/2169946.html http://www.cnblogs ...
- 网络复习之TCP
可靠传输的工作原理 1 停止等待协议 每发送完一个分组,就停止发送,等待对方确认.出现差错,超时重传. 1.1 暂时保留已发送的分组的副本 1.2 分组和确认分组必须进行编号 ...
- JS 的点点滴滴
1. ||含义 : 返回第一个有效值 eg : <script type="text/javascript"> var a=""; var c = ...
- javax.naming.NameNotFoundException
2015-08-27 09:53:16,463 [localhost-startStop-1] DEBUG [org.springframework.jndi.JndiTemplate] - Look ...