-
Notifications
You must be signed in to change notification settings - Fork 2
/
HDU-dx2012-9-1006.cpp
99 lines (93 loc) · 1.66 KB
/
HDU-dx2012-9-1006.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
ID: mfs6174
email: mfs6174@gmail.com
PROG: ti
LANG: C++
*/
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<deque>
#include<iomanip>
#include<cmath>
#include<set>
#define sf scanf
#define pf printf
#define llg long long
const int dt=210000;
using namespace std;
//ifstream inf("ti.in");
//ofstream ouf("ti.out");
const int maxlongint=2147483647;
int i,j,k,t,n,m,ngt,mx,p,mm,zhi;
bool f[2][500000];
double dm,gt;
int dd[300];
int zu,zz;
inline int mabs(int x)
{
if (x<0)
return -x;
else
return x;
}
int main()
{
freopen("ti.in","r",stdin);
sf("%d",&zu);
for (zz=1;zz<=zu;zz++)
{
sf("%lf%d",>,&n);
if (gt<0)
gt=gt-0.00005;//This is important! pos+eps/10*5 neg-
else
gt=gt+0.00005;
ngt=(gt)*10000;
mx=0;
for (i=1;i<=n;i++)
{
sf("%lf",&dm);
if (dm<0)
dm=dm-0.00005;
else
dm=dm+0.00005;
dd[i]=(dm)*10000;
if (dd[i]<0)
mx+=dd[i];
}
sort(&dd[1],&dd[n+1]);
memset(f,0,sizeof(f));
f[0][dt]=true;
mm=maxlongint;
for (i=1,p=1;i<=n;i++,p=1-p)
for (j=mx;j<20000;j++)
{
if (j-dd[i]>=mx&&j-dd[i]<20000)
f[p][j+dt]=f[1-p][j+dt]||f[1-p][j-dd[i]+dt];
else
f[p][j+dt]=f[1-p][j+dt];
if (f[p][j+dt])
{
if (mabs(j-ngt)<mm)
{
mm=mabs(j-ngt);
zhi=j;
}
else
if (mabs(j-ngt)==mm)
{
if (j<zhi)
zhi=j;
}
}
}
pf("%.4lf\n",zhi/10000.0);
}
return 0;
}