HDU 4870 Rating (Gaussian deyuan)
HDU 4870 Rating
Question Link
A person registers two accounts, and the initial rating is 0. He plays the game with the low score each time. After winning the game, he adds 50 points and deducts 100 points. The winning rate is p, he will hit the game until he scored 1000 points on the first day and asked about the expectations of the game.
Train of Thought: f (I, j) indicates I> = j, the first number is I, and the second number is j, to achieve the goal, then we can list the transfer as f (I, j) = p f (I ', j') + (1-p) f (I '+ j'') + 1
F (I ', j') corresponds to the State in which the bonus points are received, and f (I '', j'') corresponds to the deduction status, 50 points can be regarded as a unit, with a total of 20*21/2 = 210 states, that is, corresponding to the 210 equations, using Gaussian elimination element to solve the equations, and solving f (0, 0) is the answer
Code:
#include
#include
#include
#include using namespace std;const double eps = 1e-9;const int N = 305;double p, a[N][N];int mark[25][25];double solve() { for (int i = 0; i < 210; i ++) {int k = i;for (; k < 210; k++) if (fabs(a[k][i]) > eps) break;for (int j = 0; j <= 210; j++) swap(a[i][j], a[k][j]);for (int j = 0; j < 210; j++) { if (i == j) continue; if (fabs(a[j][i]) > eps) {double x = a[j][i] / a[i][i];for (int k = i; k <= 210; k++) { a[j][k] -= a[i][k] * x;} }} } return a[0][210] / a[0][0];}void build() { memset(a, 0, sizeof(a)); for (int i = 0; i < 20; i++) {for (int j = 0; j < i; j++) { int u = mark[i][j]; a[u][u] = 1; a[u][210] = 1; int v = mark[i][max(0, j - 2)]; a[u][v] -= (1 - p); v = mark[i][j + 1]; a[u][v] -= p;}int u = mark[i][i];a[u][u] = 1;a[u][210] = 1;int v = mark[i][max(0, i - 2)];a[u][v] -= (1 - p);v = mark[i + 1][i];a[u][v] -= p; }}int main() { int cnt = 0; memset(mark, -1, sizeof(mark)); for (int i = 0; i < 20; i++) {for (int j = 0; j <= i; j++) { mark[i][j] = cnt; cnt++;} } while (~scanf("%lf", &p)) {build();printf("%.6lf\n", solve()); } return 0;}