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 ...
随机推荐
- Linux 中使用 dd 测试磁盘性能
翻译自 : Linux I/O Performance Tests using dd 基本说明 dd 可以用来做简单的低级别复制文件. 这样做, 一般都是可一直直接访问设备文件. 需要说明的是, 错误 ...
- 【Mysql优化】索引覆盖
索引覆盖 是指 如果查询的列恰好是索引的一部分,那么查询只需要在索引文件上进行,不需要回行到磁盘再找数据.这种查询速度非常快,称为”索引覆盖”,比平时的查询少一次到磁盘读数据的操作.(索引正好覆盖到查 ...
- 【转】gif文件格式详解
1.概述 ~~~~~~~~ GIF(Graphics Interchange Format,图形交换格式)文件是由 CompuServe公司开发的图形文件格式,版权所有,任何商业目的使用均须 Comp ...
- 74cms 注入exp
遇到就瞎写了一个: #!/usr/bin/env python #encoding:utf-8 #by i3ekr import requests,optparse,re parse = optpar ...
- Python自动化运维 - Django(三)CSRF - Cookie&Session
CSRF跨站请求伪造 CSRF跨站点请求伪造(Cross—Site Request Forgery),跟XSS攻击一样,存在巨大的危害性,你可以这样来理解:攻击者盗用了你的身份,以你的名义发送恶意请求 ...
- 原始套接字&&数据链路层访问
1. 原始套接字能力: (1) 进程可以读写ICMP,IGMP等分组,如ping程序: (2) 进程可以读写内核不处理协议字段的ipv4数据报:如OSPF等: (3) 进程可以使用IP_HDRINCL ...
- webview loadRequest
// 所构建的NSURLRequest具有一个依赖于缓存响应的特定策略,cachePolicy取得策略,timeoutInterval取得超时值 [self.yourSite loadRequest: ...
- C基础 读写锁中级剖析
引言 读写锁 是为了 解决, 大量 ''读'' 和 少量 ''写'' 的业务而设计的. 读写锁有3个特征: 1.当读写锁是写加锁状态时,在这个锁被解锁之前,所有试图对这个锁加锁的线程都会被阻塞 2.当 ...
- vue-router 基础
安装 NPM npm install vue-router 如果在一个模块化工程中使用它,必须要通过 Vue.use() 明确地安装路由功能: import Vue from 'vue' import ...
- Memcached内存缓存技术
Memcached是什么,有什么作用? Memcached是一个开源的.高性能的内存缓存软件,从名称上看Mem就是内存的意思,而Cache就是缓存的意思. Memcached通过在事先规划好的内存空间 ...