Approximations

Time Limit: 2000MS   Memory Limit: 131072K
Total Submissions: 419   Accepted: 23

Description

For any decimal fraction, we can obtain a set of approximations of different accuracy by mean of rounding. Take 0.2503 for example, we have the following approximations:

  • 0.2503
  • 0.250
  • 0.25
  • 0.3
  • 0.

If two fractions A and B can both be rounded to C, we call C a common approximation of A and B. Two fractions may have more than one common approximations, each having a distinct accuracy. For example, 0.2503 and 0.2504 have common approximations 0.250 and 0.25. The accuracy of the former is 10−3, while that of the latter is 10−2. Among all common approximations of two fractions, there is one that has the highest accuracy, and we call it the most accurate common approximation (MACA) of the two fractions. By this definition, the MACA of 0.2503 and 0.2504 is 0.250.

Given N fractions Ai (1 ≤ i ≤ N) in the range [0, 0.5), find a fraction x that maximizes the sum of −log10 (the accuracy of the MACA of Ai and x). Report that maximized sum.

Input

The first line contains one integer NN ≤ 100000.
Each of the next N lines contains a decimal fraction Ai. The total number of digits of the N decimal fractions doesn't exceed 400000. There is always a radix point, so zero is "0." instead of "0".

Output

One integer, the maximized sum.

Sample Input

4
0.250
0.2506
0.25115
0.2597

Sample Output

11

Hint

x = 0.25115.

Source


 

董华星在他09年的论文里说可以用字典树写。。我试着写了下,然而感觉题目是不是给的范围有问题啊。测了好多样例没问题。欢迎各位大佬给个样例测测0 0。

代码如下:

 #include<cstdio>
#include<iostream>
#include<cstring>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 1000000007
#define INF 0x3f3f3f3f
#define next nexted
using namespace std;
const int N=1e5+;
const int M=4e5+;
int next[M][];
int num[M];
char s[M];
int n,m,k;
int root,ttot;
void tadd(char *s,int root)
{
int now=root,p;
int len=strlen(s);
for(int i=;i<len;i++)
{
p=s[i]-'';
if(next[now][p]==)
{
next[now][p]=++ttot;
}
now=next[now][p];
num[now]++;
}
return ;
}
int ans,prenode;
void dfs(int now,int prenum)
{
int nownum,p;
for(int i=;i<;i++)
{
nownum=prenum;
p=next[now][i];
if(i==)
{
if(prenode!=)
{
prenode=next[prenode][];
if(prenode!=)
{
for(int j=;j<;j++)
if(next[prenode][j]!=)
nownum+=num[next[prenode][j]];
}
}
}
else
{
if(next[now][i-]!=)
for(int j=;j<;j++)
{
if(next[next[now][i-]][j]!=)
{
nownum+=num[next[next[now][i-]][j]];
if(i->=)
{
nownum+=num[next[next[now][i-]][j]];
}
} }
}
if(i!=)
{
prenode=next[now][i-];
}
if(p!=)
{
nownum+=num[p];
for(int j=;j<;j++)
{
if(next[p][j]!=)
{
nownum-=num[next[p][j]];
}
}
if(i>=)
nownum+=num[p];
if(nownum>ans)
ans=nownum;
// cout<<i<<" "<<nownum<<endl;
dfs(p,nownum);
}
else
{
if(nownum>ans)
ans=nownum;
}
}
return ;
}
int main()
{
scanf("%d",&n);
ttot=root=;
for(int i=;i<=n;i++)
{
scanf("%s",s);
tadd(s+,root);
}
ans=;
dfs(root,);
printf("%d\n",ans);
return ;
}

poj 3464(Trie)Approximations的更多相关文章

  1. poj 1816 (Trie + dfs)

    题目链接:http://poj.org/problem?id=1816 思路:建好一颗Trie树,由于给定的模式串可能会重复,在原来定义的结构体中需要增加一个vector用来记录那些以该节点为结尾的字 ...

  2. poj 2945 trie树统计字符串出现次数

    用记录附加信息的val数组记录次数即可. trie的原理:每个可能出现的字目给一个编号c,那么整个树就是一个c叉树 ch[u][c]表示 节点u走c边过去之后的节点 PS:trie树还有种动态写法,使 ...

  3. poj 2001 trie

    第一道trie 还需要写题来建立自己的代码习惯. #include <cstdio> #include <vector> #include <algorithm> ...

  4. POJ 3630 trie树

    Phone List Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26559 Accepted: 8000 Descripti ...

  5. POJ 2945 trie树

    Find the Clones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 7704 Accepted: 2879 Descr ...

  6. Phone List POJ 3630 Trie Tree 字典树

    Phone List Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 29416   Accepted: 8774 Descr ...

  7. POJ 2513 trie树+并查集判断无向图的欧拉路

    生无可恋 查RE查了一个多小时.. 原因是我N define的是250500 应该是500500!!!!!!!!! 身败名裂,已无颜面对众人.. 吐槽完了 我们来说思路... 思路: 判有向图能否形成 ...

  8. POJ 3464 ACM Computer Factory

    ACM Computer Factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4829 Accepted: 1641 ...

  9. hdu 1671&& poj 3630 (trie 树应用)

    Phone List Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 25280   Accepted: 7678 Descr ...

随机推荐

  1. 【51NOD-0】1018 排序

    [算法]排序 #include<cstdio> #include<algorithm> using namespace std; ]; int main() { scanf(& ...

  2. bzoj 1588 bst

    用set存下就好了. /************************************************************** Problem: 1588 User: BLADE ...

  3. poj 1062 昂贵的聘礼 (dijkstra最短路)

    题目链接:http://poj.org/problem?id=1062 昂贵的聘礼 Time Limit: 1000MS   Memory Limit: 10000K Total Submission ...

  4. CTF线下赛AWD模式下的生存技巧

    作者:Veneno@Nu1L 稿费:200RMB 投稿方式:发送邮件至linwei#360.cn,或登陆网页版在线投稿 原文:https://www.anquanke.com/post/id/8467 ...

  5. Python【模块】importlib,requests

    内容概要:      模仿django中间件的加载方式      importlib模块      requests模块  rsplit()   用实际使用的理解来解释两个模块 importlib模块 ...

  6. MACHINE_START与MACHINE_END【转】

    转自:http://blog.csdn.net/cxw3506/article/details/8475965 版权声明:本文为博主原创文章,未经博主允许不得转载. 在移植Linux时,有个结构体需要 ...

  7. Linux 内核通知链随笔【中】【转】

    转自:http://blog.chinaunix.net/uid-23069658-id-4364171.html 关于内核通知链不像Netlink那样,既可以用于内核与用户空间的通信,还能用于内核不 ...

  8. c++设计模式系列----builder模式

    看了好几处关于builder模式的书和博客,总感觉不是很清楚,感觉不少书上的说的也不是很准确.最后还是看回圣经<设计模式>.看了好久终于感觉明白了一点了. 意图: builder模式提出的 ...

  9. Ruby-Clamp

    require "clamp" class ClampTest < Clamp::Command # 1.命令行的参数使用主要分两类,一种是参数名称后面带参数值的方式, #我 ...

  10. CentOS下配置FTP

    http://www.cnblogs.com/zhenmingliu/archive/2012/04/25/2470646.html 常见错误: 1.FTP服务器已经拒绝 解决方案 # setenfo ...