字典树,可惜比赛的时候有两句话写倒了;

害得我调了一个小时;

今天不宜做题 = =

代码:

 #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的更多相关文章

  1. Cellphone Typing 字典树

    Cellphone Typing Time Limit: 5000ms Memory Limit: 131072KB   This problem will be judged on UVA. Ori ...

  2. BNU 27847——Cellphone Typing——————【字典树】

    Cellphone Typing Time Limit: 5000ms Memory Limit: 131072KB This problem will be judged on UVA. Origi ...

  3. UVA 11988 Broken Keyboard (a.k.a. Beiju Text)(链表)

    题目代号:UVA 11988 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&pa ...

  4. 【OI】WERTYU UVa 10082

    题目: A common typing error is to place the hands on the keyboard one row to the right of the correct ...

  5. Python标准库--typing

    作者:zhbzz2007 出处:http://www.cnblogs.com/zhbzz2007 欢迎转载,也请保留这段声明.谢谢! 1 模块简介 Python 3.5 增加了一个有意思的库--typ ...

  6. 最牛的打字效果JS插件 typing.js

    最新在做公司的一个项目,需要实现一个敲打代码的动画效果,粗意味比较简单,果断自己直接开写,写着写着发现是一个坑.需要支持语法高亮,并不能直接简单的用setTimeout来动态附件innerHTML.苦 ...

  7. Monkey Patch/Monkey Testing/Duck Typing/Duck Test

    Monkey Patch Monkey Testing Duck Typing Duck Test

  8. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  9. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

随机推荐

  1. arcgis通过 Python 使用工具 获得结果信息

    通过 Python 使用工具 ArcGIS 10 每个地理处理工具都具有一组固定的参数,这些参数为工具提供执行所需的信息.工具通常具有定义一个或多个数据集的输入参数,这些数据集一般用于生成新的输出数据 ...

  2. js函数、表单验证

    惊天bug!!!在script里面只要有一点点错误,就都不执行了!!!所以每写一个方法,就跑一下,因为这个书写疏忽导致的bug不可估量!!! [笑哭,所以我才这么讨厌js么,后来真心的是一点都不想再看 ...

  3. 重命名计算机名称导致TFS版本管理下的工作区问题的修复

    1.问题 若在本地已有工作区之后,此时修改计算机名称重启生效后,打开本地的项目解决方案,输出窗口会提示如下图: 2.解决 输入命令:tf workspaces /collection:http://1 ...

  4. c++ 学习之const专题之const成员函数

    一些成员函数改变对象,一些成员函数不改变对象. 例如: int Point::GetY() { return yVal; } 这个函数被调用时,不改变Point对象,而下面的函数改变Point对象: ...

  5. 类库探源——System.Math 和 Random

    一.System.Math Math类:为三角函数.对数函数和其他通用数学函数提供常数和静态方法 命名空间: System 程序集 :   mscorlib.dll 继承关系: 常用属性: Math. ...

  6. new Date() 倒计时

    js中单独调用new Date() 显示的结果是:Fri May 20 2015 20:00:00 GMT+0800这种格式的时间 JS获取当前时间戳的方法 JavaScript 获取当前时间戳: 第 ...

  7. 14_输出映射2_resultMap

    [resultMap] 如果查询出来的列名和pojo的属性名不一致,通过定义一个resultMap对列名和pojo属性名之间做一个映射列表. 1.定义resultMap,(在UserMapper.xm ...

  8. identifier not found error on function call

    在C++工程中,自定义一个方法 void fgetsDemo(),在main 方法中调用,源代码如下: #include "stdafx.h" #include <stdio ...

  9. Sdut 2416 Fruit Ninja II(山东省第三届ACM省赛 J 题)(解析几何)

    Time Limit: 5000MS Memory limit: 65536K 题目描述 Haveyou ever played a popular game named "Fruit Ni ...

  10. 第3章文件I/O总结

    1. open和create函数在fcntl.h中,close.lseek.read.write函数在unistd.h中 open函数通过进程有效用户ID判断读文件的权限 可以调用access函数判断 ...