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 ...
随机推荐
- HDU 1372 Knight Moves (广搜)
题目链接 Problem Description A friend of you is doing research on the Traveling Knight Problem (TKP) whe ...
- Git 常用命令(二)
用 git init 在目录中创建新的 Git 仓库. $ mkdir test $ cd test/ $ git init Initialized empty Git repository in ...
- Angular2.0 基础: User Input
1.Angular 2.0 中的变量 对输入值的获取,我们可以通过$event 来获取,也可以通过变量来获取. template: ` <input (keyup)="onKey($e ...
- Bitmap算法应用实例(转)
关于数据库查询工作,例如有如下数据库表 要想统计所有90后的程序员该怎么做呢?用一条求交集的SQL语句即可: Select count(distinct Name) as 用户数 from table ...
- Python自动化运维 - Django(二)Ajax基础 - 自定义分页
Ajax基础 AJAX 不是新的编程语言,而是一种使用现有标准的新方法. AJAX 是与服务器交换数据并更新部分网页的艺术,在不重新加载整个页面的情况下. 什么是Ajax AJAX = 异步 Java ...
- [Leetcode Week16]Insertion Sort List
Insertion Sort List 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/insertion-sort-list/description/ ...
- MySQL多线程复制故障(slave_pending_jobs_size_max)
MySQL多线程复制故障(slave_pending_jobs_size_max) http://www.xuchanggang.cn/archives/1079.html
- [LabVIEW架构]ActorFramework(一)
前言 小黑结婚回来第二周了,每天忙于程序设计,时间比较紧张,所以文章一直没出来,也算憋大招了. 近期小黑将与大家一起认识一下ActorFramework,既是对自己一段时间写AF程序的总结,也是梳理, ...
- aspxgridview只编辑某一列然后更新
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="IsAllowDeliver ...
- 4.Python3标准库--算法
(一)functools:管理函数的工具 import functools ''' functools模块提供了一些工具来管理或扩展和其他callable对象,从而不必完全重写 ''' 1.修饰符 f ...