HDU 4870 Rating(高斯消元)

HDU 4870

Rating

高斯消元。变量不多。

Rating

Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 166 Accepted Submission(s): 87 Special Judge

Problem Description

A little girl loves programming competition very much. Recently, she has found a new kind of programming competition named “TopTopTopCoder”. Every user who has registered in “TopTopTopCoder” system will have a rating, and the initial value of rating equals to zero. After the user participates in the contest held by “TopTopTopCoder”, her/his rating will be updated depending on her/his rank. Supposing that her/his current rating is X, if her/his rank is between on 1-200 after contest, her/his rating will be min(X+50,1000). Her/His rating will be max(X-100,0) otherwise. To reach 1000 points as soon as possible, this little girl registered two accounts. She uses the account with less rating in each contest. The possibility of her rank between on 1 - 200 is P for every contest. Can you tell her how many contests she needs to participate in to make one of her account ratings reach 1000 points?

Input

There are several test cases. Each test case is a single line containing a float number P (0.3 <= P <= 1.0). The meaning of P is described above.

Output

You should output a float number for each test case, indicating the expected count of contest she needs to participate in. This problem is special judged. The relative error less than 1e-5 will be accepted.

Sample Input

1.000000 0.814700

Sample Output

39.000000 82.181160

Author

FZU

Source

2014 Multi-University Training Contest 1

其实变量数很少,直接高斯消元。   其中在求解过程判断了 < eps 返回无解,WA了好多发。 注释掉就AC了。  
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/* ***************

Author :kuangbin

Created Time :2014/7/22 23:33:49

File Name :E:\2014ACM\比赛\2014多校训练\2014多校1\HDU4870.cpp

************************************************ */

#include <stdio.h>

#include <string.h>

#include <iostream>

#include <algorithm>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <string>

#include <math.h>

#include <stdlib.h>

#include <time.h>

using namespace std;

#define eps 1e-9

const int MAXN=420;

double a[MAXN][MAXN],x[MAXN];//方程的左边的矩阵和等式右边的值,求解之后x存的就是结果

int equ,var;//方程数和未知数个数

/*

*返回0表示无解,1表示有解

*/

int Gauss()

{

int i,j,k,col,max_r;

for(k=0,col=0;k<equ&&col<var;k++,col++)

{

max_r=k;

for(i=k+1;i<equ;i++)

if(fabs(a[i][col])>fabs(a[max_r][col]))

max_r=i;

// if(fabs(a[max_r][col])<eps)return 0;

if(k!=max_r)

{

for(j=col;j<var;j++)

swap(a[k][j],a[max_r][j]);

swap(x[k],x[max_r]);

}

x[k]/=a[k][col];

for(j=col+1;j<var;j++)a[k][j]/=a[k][col];

a[k][col]=1;

for(i=0;i<equ;i++)

if(i!=k)

{

x[i]-=x[k]*a[i][col];

for(j=col+1;j<var;j++)a[i][j]-=a[k][j]*a[i][col];

a[i][col]=0;

}

}

return 1;

}

int id[22][22];

int main()

{

//freopen("1010.in","r",stdin);

//freopen("out.txt","w",stdout);

int cnt = 0;

for(int i = 0;i <= 20;i++)

for(int j = 0;j <= 20;j++)

{

if(i > j)continue;

if(i == 20 && j == 20)continue;

id[i][j] = cnt++;

}

equ = var = cnt;

double p;

while(scanf("%lf",&p) == 1)

{

memset(a,0,sizeof(a));

for(int i = 0;i <= 20;i++)

for(int j = 0;j <= 20;j++)

{

if(i > j)continue;

if(i == 20 && j == 20)continue;

int u = id[i][j];

a[u][u] = 1.0;

if(i == 20 || j == 20)

{

x[u] = 0.0;

continue;

}

x[u] = 1.0;

int nx = i+1;

if(nx <= j)

a[u][id[nx][j]] -= p;

else a[u][id[j][nx]] -= p;

nx = max(0,i-2);

a[u][id[nx][j]] -= (1-p);

}

Gauss();

printf("%.6lf\n",x[0]);

}

return 0;

}
------ 本文结束------
  • 本文作者: kuangbin
  • 本文链接: 284.html
  • 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!
0%