Approximations
| Time Limit: 2000MS |
|
Memory Limit: 131072K |
| Total Submissions: 419 |
|
Accepted: 23 |
Description
For all decimal fraction, we can obtain a set of approximations of different accuracy by mean of rounding. Take 0.2503 For example and we have the following approximations:
If fractions A and B can both be rounded to C , we call C a common approximation of a and B . Fractions May has more than one common approximations and each has a distinct accuracy. For example, 0.2503 and 0.2504 has common approximations 0.250 and 0.25. The accuracy of the former is 10?3 and while that's the latter is 10?2. Among all common approximations of both fractions, there is one and the highest accuracy, and we call it the Most accurate common approximation (MACA) of the of the fractions. By this definition, the MACA of 0.2503 and 0.2504 are 0.250.
Given n fractions Ai (1≤ i ≤ N) in the range [0, 0.5), find a fraction x tha T 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
40.2500.25060.251150.2597
Sample Output
11
Hint
x= 0.25115.
Source
POJ monthly--2007.11.25, Yang Yi
Donghuazing in his 09-year paper that can be written in a dictionary tree. I tried to write it down, but I felt that the topic was not a question of scope. A lot of samples have been tested. Welcome to the big guy to give a sample test 0 0.
The code is as follows:
1#include <cstdio>2#include <iostream>3#include <cstring>4 #defineCLR (x) memset (x,0,sizeof (x))5 #defineclr_1 (x) memset (x,-1,sizeof (x))6 #defineLL Long Long7 #defineMoD 10000000078 #defineINF 0x3f3f3f3f9 #defineNext nextedTen using namespacestd; One Const intn=1e5+Ten; A Const intm=4e5+Ten; - intnext[m][Ten]; - intNum[m]; the CharS[m]; - intn,m,k; - intRoot,ttot; - voidTaddChar*s,introot) + { - intnow=root,p; + intlen=strlen (s); A for(intI=0; i<len;i++) at { -p=s[i]-'0'; - if(next[now][p]==0) - { -next[now][p]=++Ttot; - } innow=Next[now][p]; -num[now]++; to } + return ; - } the intAns,prenode; * voidDfsintNowintprenum) $ {Panax Notoginseng intnownum,p; - for(intI=0;i<Ten; i++) the { +nownum=Prenum; Ap=Next[now][i]; the if(i==0) + { - if(prenode!=0) $ { $prenode=next[prenode][9]; - if(prenode!=0) - { the for(intj=5;j<Ten; j + +) - if(next[prenode][j]!=0)Wuyinownum+=Num[next[prenode][j]]; the } - } Wu } - Else About { $ if(next[now][i-1]!=0) - for(intj=5;j<Ten; j + +) - { - if(next[next[now][i-1]][j]!=0) A { +nownum+=num[next[next[now][i-1]][j]]; the if(I-1>=5) - { $nownum+=num[next[next[now][i-1]][j]]; the } the } the the } - } in if(i!=0) the { theprenode=next[now][i-1]; About } the if(p!=0) the { thenownum+=Num[p]; + for(intj=5;j<Ten; j + +) - { the if(next[p][j]!=0)Bayi { thenownum-=Num[next[p][j]]; the } - } - if(i>=5) thenownum+=Num[p]; the if(nownum>ans) theans=Nownum; the //cout<<i<< "" <<nownum<<endl; - DFS (p,nownum); the } the Else the {94 if(nownum>ans) theans=Nownum; the } the }98 return ; About } - intMain ()101 {102scanf"%d",&n);103ttot=root=0;104 for(intI=1; i<=n;i++) the {106scanf"%s", s);107Tadd (s+2, root);108 }109ans=0; theDFS (Root,0);111printf"%d\n", ans); the return 0;113}View Code
POJ 3464 (Trie) approximations