uva 12526 - Cellphone Typing
字典树,可惜比赛的时候有两句话写倒了;
害得我调了一个小时;
今天不宜做题 = =
代码:
#include<cstdio>
#include<cstring>
#define maxn 2600009
using namespace std; struct node
{
bool flag;
int cnt;
node *a[];
} no[maxn]; char s[];
int ans,nonocount;
node *newnode()
{
node *p=no+nonocount++;
p->flag=;
p->cnt=;
for(int i=; i<; i++)
p->a[i]=NULL;
return p;
} void insert(node *rt,char *s)
{
int l=strlen(s);
int i=;
while()
{
if(rt->a[s[i]-'a']==NULL) rt->a[s[i]-'a']=newnode();
rt=rt->a[s[i]-'a'];
rt->cnt++;
i++;
if(i==l)
{
rt->flag=;
break;
}
}
} void query(node *rt)
{
int cot=;
for(int i=; i<; i++)
{
if(rt->a[i]!=NULL)
{
cot++;
query(rt->a[i]);
}
}
if(cot>)
{
ans+=rt->cnt;
if(rt->flag==)ans--;
}
else if(rt->flag==)
{
ans+=(rt->cnt-);
}
} int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
nonocount=;
node *p=newnode();
for(int i=; i<n; i++)
{
scanf("%s",s);
insert(p,s);
}
ans=;
query(p);
printf("%.2lf\n",(double)(ans+n)/n);
}
return ;
}
uva 12526 - Cellphone Typing的更多相关文章
- Cellphone Typing 字典树
Cellphone Typing Time Limit: 5000ms Memory Limit: 131072KB This problem will be judged on UVA. Ori ...
- BNU 27847——Cellphone Typing——————【字典树】
Cellphone Typing Time Limit: 5000ms Memory Limit: 131072KB This problem will be judged on UVA. Origi ...
- UVA 11988 Broken Keyboard (a.k.a. Beiju Text)(链表)
题目代号:UVA 11988 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&pa ...
- 【OI】WERTYU UVa 10082
题目: A common typing error is to place the hands on the keyboard one row to the right of the correct ...
- Python标准库--typing
作者:zhbzz2007 出处:http://www.cnblogs.com/zhbzz2007 欢迎转载,也请保留这段声明.谢谢! 1 模块简介 Python 3.5 增加了一个有意思的库--typ ...
- 最牛的打字效果JS插件 typing.js
最新在做公司的一个项目,需要实现一个敲打代码的动画效果,粗意味比较简单,果断自己直接开写,写着写着发现是一个坑.需要支持语法高亮,并不能直接简单的用setTimeout来动态附件innerHTML.苦 ...
- Monkey Patch/Monkey Testing/Duck Typing/Duck Test
Monkey Patch Monkey Testing Duck Typing Duck Test
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
随机推荐
- 基于anyrtc的sdk实现直播连麦互动
基于anyrtc的sdk实现直播连麦互动 前言 1.由于粘贴了较大的代码,造成内容比较长,可能会花费您较长的时间. 2.项目里面没有做权限判断,所以如果发现有页面发生崩溃可能是权限没有打开,请打开权限 ...
- html 笔记
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- 使用WebView显示网页
简单的页面跳转 package com.example.webtest; import java.security.PublicKey; import android.support.v7.app.A ...
- 广告系统中weak-and算法原理及编码验证
wand(weak and)算法基本思路 一般搜索的query比较短,但如果query比较长,如是一段文本,需要搜索相似的文本,这时候一般就需要wand算法,该算法在广告系统中有比较成熟的应 该,主要 ...
- JavaScript学习笔记--ES6学习(四) 字符串的扩展
ES6对字符串进行了一些扩展,主要表现在对Unicode 大于\uFFFF的字符的处理上. 1. ES6中字符的Unicode表示方法 在ES5中,字符串的Unicode表示方法: \uxxxx . ...
- Javascript 数组自定义排序,并获取排序后的保存原索引的同序数组(堆排序实现)
比如数组A: [ 0: 5, 1: 2, 2: 4, 3: 3, 4: 1 ] 排序后的结果为:[1, 2, 3, 4, 5],但是有时候会有需求想要保留排序前的位置到一个同位数组里,如前例则为:[4 ...
- js判断主流浏览器类型和版本号
如今的互联网中,浏览器可以说是太多太多了,但是大部分都是换壳不换心,基本上主流的浏览器还是火狐,谷歌,IE,safrai这几种比较常见,所以在我们的开发中,有时候需要遇到判断用户正在使用什么浏览器以及 ...
- javascript 中caller,callee,call,apply 的概念[转载]
在提到上述的概念之前,首先想说说javascript中函数的隐含参数:arguments Arguments : 该对象代表正在执行的函数和调用它的函数的参数. [function.]argument ...
- spring Aop 注解
个人理解: spring Aop 是什么:面向切面编程,类似于自定义拦截操作,支持拦截之前操作@Before,拦截之后操作@After,拦截环绕操作@Around. 什么情况下使用spring Aop ...
- (转)UIColor 的使用
os开发-UIColor的使用. 在ios开发中,经常遇到对UIColor的相关操作. 比如这样 self.backgroundColor = [UIColorredColor]; 这里的redCol ...