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. 【bzoj】1927 [Sdoi2010]星际竞速

    [算法]最小费用最大流 [题解]跟滑雪略有类似,同样因为可以重复所以不是最小路径覆盖. 连向汇的边容量为1足矣,因为一个点只会出去一次(路径结束). bzoj 1927 [Sdoi2010]星际竞速 ...

  2. POJ 3279 Fliptile ( 开关问题)

    题目链接 Description Farmer John knows that an intellectually satisfied cow is a happy cow who will give ...

  3. mysql增删

    create table msg (id int, name varchar(10)); 插入语句 insert into msg values(1,'root'); insert into msg( ...

  4. java===java基础学习(14)---封装

    package dog; public class Demo4 { public static void main(String []args) { Worker w1= new Worker(&qu ...

  5. 真正的上锁前,为何要调用preempt_disable()来关闭抢占的case【转】

    转自:http://blog.csdn.net/kasalyn/article/details/11473885 static inline void raw_spin_lock(raw_spinlo ...

  6. python windows下安装celery调度任务时出错

    由于celery 4.0不支持windows系统.所以用命令pip install Celery安装的celery是最新版4.0的不能在windows下运行. 在windows命令窗口运行: cele ...

  7. hadoop中setOutputKeyClass和setOutputValueClass里类型

    初学mapreduce programing,纠结一天的问题如下: job.setOutputKeyClass和job.setOutputValueClas在默认情况下是同时设置map阶段和reduc ...

  8. python内建方法

    abs all any apply basestring bin bool buffer bytearray bytes callable chr classmethod cmp coerce com ...

  9. JDBC数据源连接池(4)---自定义数据源连接池

    [续上文<JDBC数据源连接池(3)---Tomcat集成DBCP>] 我们已经 了解了DBCP,C3P0,以及Tomcat内置的数据源连接池,那么,这些数据源连接池是如何实现的呢?为了究 ...

  10. shell 中的<,<<,>,>>

    相信熟悉linux的童鞋不会对这四个符合陌生,shell脚本的文件流有时候真的挺容易搞晕人的,下面我们一起了解一下吧 参考链接:http://www.cnblogs.com/chengmo/archi ...