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

害得我调了一个小时;

今天不宜做题 = =

代码:

 #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. Android开发之线程池使用总结

    线程池算是Android开发中非常常用的一个东西了,只要涉及到线程的地方,大多数情况下都会涉及到线程池.Android开发中线程池的使用和Java中线程池的使用基本一致.那么今天我想来总结一下Andr ...

  2. easy_painting

    最近感觉结构,比例抓的容易多了.

  3. Android_Intent_passObject

    方法4. 把基本的数据类型封装到一个对象中,然后通过intent传递该对象需要考虑对Person对象进行序列化 MainActivity: package com.example.day06_acti ...

  4. C#读取Excel文档

    上面分别是Excel文档的内容和读取结果: 奉上C#源代码: using System; using System.Data; using System.Data.OleDb; namespace R ...

  5. 20151222jquery学习笔记--验证注册表单

    $(function () { $('#search_button').button({ icons : { primary : 'ui-icon-search', }, }); $('#reg'). ...

  6. PHP和MYSQL的编码问题

    http://blog.csdn.net/martinkro/article/details/5352474 1 MYSQL中的字符集概念  Mysql的字符集里有两个概念,一个是"Char ...

  7. windows8 8.1 安装完 ubuntu无法挂载 ntfs分区 解决方法

    windows8 8.1 安装完 ubuntu无法挂载 ntfs分区 解决方法: 最近安装完发现8.1系统后,ubuntu无法加载以前的ntfs分区了,特别是我添加到了/etc/fstab里面了 导致 ...

  8. CWnd::UpdateData

    CWnd::UpdateData 格式: BOOL UpdateData( BOOL bSaveAndValidate = TRUE ); 描述:调用该成员函数初始化在对话框中的数据,或检索和验证对话 ...

  9. kindeditor-4.1.10在线编辑器的使用[多个]

    <script type="text/javascript" charset="utf-8" src="../../Editor/kindedi ...

  10. OpenGL_Qt学习笔记之_05(纹理映射)(转)

    转自:http://www.cnblogs.com/tornadomeet/archive/2012/08/24/2654719.html 纹理映射基础知识 什么叫纹理映射,一开始我也不明白,感觉这个 ...