-
Notifications
You must be signed in to change notification settings - Fork 2
/
HDU-dx5-1011.cpp
116 lines (107 loc) · 1.83 KB
/
HDU-dx5-1011.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
ID: mfs6174
PROG: ti
LANG: C++
*/
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;
//ifstream inf("ti.in");
//ofstream ouf("ti.out");
const int maxlongint=2147483647;
int i,j,k,t,n,p;
double sd,z,ss,mm,m,se,mx,sdx,ssx;
double shu[11000],shux[11000];
inline double ff(double x)
{
return x*x;
}
int main()
{
freopen("ti.in","r",stdin);
while (scanf("%d%d",&p,&n)!=EOF)
{
if (p==1)
{
ss=0;
for (i=1;i<=n;i++)
{
scanf("%lf",&shu[i]);
ss+=shu[i];
}
m=ss/n;
sd=0;
for (i=1;i<=n;i++)
sd+=ff(shu[i]-m);
sd=sd/n;
sd=sqrt(sd);
for (i=1;i<n;i++)
printf("%.2lf ",(shu[i]-m)/sd);
printf("%.2lf\n",(shu[n]-m)/sd);
continue;
}
if (p==2)
{
ss=0;
scanf("%lf",&mm);
for (i=1;i<=n;i++)
{
scanf("%lf",&shu[i]);
ss+=shu[i];
}
m=ss/n;
sd=0;
for (i=1;i<=n;i++)
sd+=ff(shu[i]-m);
sd=sd/(n-1);
sd=sqrt(sd);
se=sd/sqrt(n);
double t=(m-mm)/se;
printf("%.2lf\n",t);
continue;
}
ssx=ss=0;
for (i=1;i<=n;i++)
{
scanf("%lf",&shux[i]);
ssx+=shux[i];
}
for (i=1;i<=n;i++)
{
scanf("%lf",&shu[i]);
ss+=shu[i];
}
m=ss/n;
sd=0;
for (i=1;i<=n;i++)
sd+=ff(shu[i]-m);
sd=sd/n;
sd=sqrt(sd);
mx=ssx/n;
sdx=0;
for (i=1;i<=n;i++)
sdx+=ff(shux[i]-mx);
sdx=sdx/n;
sdx=sqrt(sdx);
double r=0;
for (i=1;i<=n;i++)
r+=(shux[i]-mx)*(shu[i]-m);
r=r/n/sdx/sd;
if (p==3)
{
printf("%.2lf\n",r);
}
else
{
double b=r*sd/sdx,a=m-b*mx;
printf("%.2lf %.2lf\n",a,b);
}
}
return 0;
}