2015
04-16

Darts

After a long week of work at the ICPC Headquarters, Bill and his friends usually go to a small pub on Friday evenings to have a couple of beers and play darts. All of them are well aware of the fact that their ability at darts decreases at the same rate as the amount of beer left in their mugs.
They always play 501, one of the easiest games. Players start with a score of N points (typically, N = 501, hence the name) and take turns throwing darts. The score of each player decreases by the value of the section hit by the dart, unless the score becomes negative, in which case it remains unchanged. The first player to reach a score of 0 wins. The figure below shows the dartboard with which the game is played.

As the clock ticks closer to midnight and they start running out of beer, everyone wonders the same: is it worth trying to aim the dart at a speci c section? Or is it better just to throw the dart at a random section on the dartboard? You are asked to deal with the question by finding out what would happen if two players (A and B) applying these two different strategies were to play against each other:

Player A throws the darts at random, and consequently they land with equal probability in each of the sections of the dartboard.
If Player B aims at a certain section, the dart has the same probability of landing in the correct one as in each of the two adjacent ones (the neighbouring regions to the left and right). Moreover, he is completely aware of his ability and sober enough to aim at the section that maximizes his probability of winning.

Given the initial score of both players, can you determine the probability that the first player wins? Of course, being the first to throw a dart might be advantageous, so the answer depends on who plays first.

The input consists of a series of lines, each containing an integer N (1<=N<=501), the initial score of both players. A case with N = 0 marks the end of the input and must not be processed.

The input consists of a series of lines, each containing an integer N (1<=N<=501), the initial score of both players. A case with N = 0 marks the end of the input and must not be processed.

5
100
0

0.136363636364 0.909090909091
0.072504908290 0.950215081962

Result  :  Accepted     Memory  :  4212 KB     Time : 796 ms

/*
* Author: Gatevin
* Created Time:  2014/8/24 11:54:43
* File Name: hehe.cpp
*/
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
const double eps(1e-8);
typedef long long lint;

#define maxn 501

int n;
double dpA[maxn + 1][maxn + 1];
double dpB[maxn + 1][maxn + 1];

int d[] = {20, 1, 18, 4, 13, 6, 10, 15, 2, 17, 3, 19, 7, 16, 8, 11, 14, 9, 12, 5};

int loop = 0;

int main()
{
memset(dpA, 0, sizeof(dpA));
memset(dpB, 0, sizeof(dpB));
for(int i = 1; i <= maxn; i++)
{
dpA[0][i] = 1;
dpB[i][0] = 1;
}
for(int i = 1; i <= maxn; i++)
{
for(int j = 1; j <= maxn; j++)
{
loop = 0;
do
{
double a = 0;
for(int k = 0; k < 20; k++)
{
if(i >= d[k])
a += dpB[i - d[k]][j];
else
a += dpB[i][j];
}
dpA[i][j] = 1 - a / 20.;
a = 0;
for(int h = 0; h < 20; h++)
{
double b = 0;
for(int k = -1; k <= 1; k++)
{
int tmp = (h + 20 + k) % 20;
if(j >= d[tmp])
b += dpA[i][j - d[tmp]];
else
b += dpA[i][j];
}
b = 1 - b / 3.;
a = max(a, b);
}
dpB[i][j] = a;
loop++;
}
while((i < 20 || j < 20) && loop <= 70);
}
}
while(scanf("%d", &n), n)
printf("%.12f %.12f\n", dpA[n][n], dpB[n][n]);
return 0;
}


loop次数去太大会超时