HDU 4870 Rating (Gaussian deyuan), hdu4870

Source: Internet
Author: User

HDU 4870 Rating (Gaussian deyuan), hdu4870
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 <cstdio>#include <cstring>#include <cmath>#include <algorithm>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;}



What algorithms are good for algorithm design competitions?

It should be ACM.
It is 8-10 algorithm questions for you. The more questions you have made in five hours, the higher the ranking. If the number of questions is the same, the more time you use.
The time calculation method is as follows:
For example, if you use question A for 20 minutes, then question B uses Question A for 30 minutes (this is the start of the game for 50 minutes) and question C for 30 minutes, so your time (penalty) is
20 + 50 + 80 = 150 minutes

Common algorithms used in competitions include:
1. Dynamic Planning
2. Search
3. Greedy
4. Graph Theory
5. Combined mathematics
6. Computational ry
7. Number Theory
And so on

Recommended
Acm.pku.edu.cn
Acm.zju.edu.cn
Acm.hdu.edu.cn
Acm.timus.ru
These OJ exercises

Better question classification (on POJ)
1. This is my favorite
Initial stage:
I. Basic Algorithms:
(1) enumeration. (poj1753, poj2965) (2008-10-27Done bitwise operation + wide search)
(2) greedy (poj1328, poj2109, poj2586)
(3) recursion and divide and conquer.
(4) recurrence.
(5) constructor. (poj3295)
(6) simulation method. (poj1068, poj2632, poj1573, poj2993, poj2996)
Ii. Graph Algorithm:
(1) depth first traversal and breadth first traversal.
(2) shortest path algorithm (dijkstra, bellman-ford, floyd, heap + dijkstra) (2008-08-29Done)
(Poj1860, poj3259, poj1062, poj2253, poj1125, poj2240)
(3) Minimum Spanning Tree Algorithm (prim, kruskal)
(Poj1789, poj2485, poj1258, poj3026)
(4) Topology Sorting (poj1094) (2008-09-01Done)
(5) maximum matching of bipartite graphs (Hungary algorithm) (poj3041, poj3020)
(6) augmented Path Algorithm for the maximum stream (KM algorithm). (poj1459, poj3436)
Iii. data structure.
(1) string (poj1035, poj3080, poj1936)
(2) sorting (fast sorting, Merge Sorting (related to the number of reverse orders), heap sorting) (poj2388, poj2299)
(3) Simple and query set applications.
(4) efficient search methods such as Hash table and binary search (number Hash, string Hash)
(Poj3349, poj3274, POJ2151, poj1840, poj2002, poj2503)
(5) Harman tree (poj3253) (2008-09-02Done)
(6) Heap
(7) trie tree (static and dynamic) (poj2513) (done, query set, Euler)
4. Simple search
(1) Deep Priority Search (poj2488, poj3083, poj3009, poj1321, poj2.pdf)
(2) breadth-first search (poj3278, poj1426, ...... the remaining full text>
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.