poj 3464(Trie)Approximations
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 N. N ≤ 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
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的更多相关文章
- poj 1816 (Trie + dfs)
题目链接:http://poj.org/problem?id=1816 思路:建好一颗Trie树,由于给定的模式串可能会重复,在原来定义的结构体中需要增加一个vector用来记录那些以该节点为结尾的字 ...
- poj 2945 trie树统计字符串出现次数
用记录附加信息的val数组记录次数即可. trie的原理:每个可能出现的字目给一个编号c,那么整个树就是一个c叉树 ch[u][c]表示 节点u走c边过去之后的节点 PS:trie树还有种动态写法,使 ...
- poj 2001 trie
第一道trie 还需要写题来建立自己的代码习惯. #include <cstdio> #include <vector> #include <algorithm> ...
- POJ 3630 trie树
Phone List Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26559 Accepted: 8000 Descripti ...
- POJ 2945 trie树
Find the Clones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 7704 Accepted: 2879 Descr ...
- Phone List POJ 3630 Trie Tree 字典树
Phone List Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 29416 Accepted: 8774 Descr ...
- POJ 2513 trie树+并查集判断无向图的欧拉路
生无可恋 查RE查了一个多小时.. 原因是我N define的是250500 应该是500500!!!!!!!!! 身败名裂,已无颜面对众人.. 吐槽完了 我们来说思路... 思路: 判有向图能否形成 ...
- POJ 3464 ACM Computer Factory
ACM Computer Factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4829 Accepted: 1641 ...
- hdu 1671&& poj 3630 (trie 树应用)
Phone List Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 25280 Accepted: 7678 Descr ...
随机推荐
- 【STSRM10】dp只会看规律
[算法]区间DP [题意]平面上有n个点(xi,yi),用最少个数的底边在x轴上且面积为S的矩形覆盖这些点(在边界上也算覆盖),n<=100. [题解]随机大数据下,贪心几乎没有错误,贪心出奇迹 ...
- C# IEqualityComparer 使用方法 Linq Distinct使用方法
创建 IEqualityComparer的接口类必须实现Equals和GetHashCode方法 public class TipComparer : IEqualityComparer<Tip ...
- LCD实验学习笔记(九):UART
s3c2440包含三个通用异步收发器,可工作于中断模式或DMA模式.每个UART包含两个64字节的FIFOs用于接收和发送数据.可编程设置波特率.1或2个停止位,5/6/7/8个数据位和奇偶校验状态. ...
- perl HTML::LinkExtor模块(2)
use LWP::Simple; use HTML::LinkExtor; $html_code = get("https://tieba.baidu.com/p/4929234512&qu ...
- Linux 入门记录:九、Linux 文件系统挂载管理
一.挂载操作 磁盘或分区创建好文件系统后,需要挂载到一个目录才能够使用. Windows 或 Mac 系统会进行自动挂载,一旦创建好文件系统后会自动挂载到系统上,Windows 上称之为 C 盘.D ...
- Context-Aware Network Embedding for Relation Modeling
Context-Aware Network Embedding for Relation Modeling 论文:http://www.aclweb.org/anthology/P17-1158 创新 ...
- mac date命令
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... [-f fmt date | [[[mm]dd ...
- 基于UDP套接字编程实例
data.h #ifndef DATA_H #define DATA_H #include <stdio.h> #include <string.h> #include < ...
- git clone命令
从远程clone一个仓库 ...知识浅薄 git clone都发现貌似用的不顺 因为我有几个git账号 但是我也不知道就是git账号是怎么保存在终端上的 所以当我需要用一个新的github账号来clo ...
- DBUtile
DBUtils是Python的一个用于实现数据库连接池的模块. 模式: - 每个线程创建一个连接,关闭(默认不关闭),线程终止时,才关闭连接. - 创建共享连接池 应用:只要写原生SQL,用户数据框连 ...