Darts
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 58   Accepted: 32   Special Judge

Description

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 specic 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.

Input

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.

Output

For each number in the input, your program should output a line containing two real numbers: the probability that A wins if A throws the first dart, and the probability that B wins if B throws the first dart. Your answers should be accurate to within an absolute or relative error of 10-8.

Sample Input

5
100
0

Sample Output

0.136363636364 0.909090909091
0.072504908290 0.950215081962 题目大意:A,B两人比赛射飞镖,每个人都有一个一样的初始分数n,两人轮流扔。投中a时,如果n大于等于a,n=n-a,否则n不变。n先为0的一方胜。
两人的策略不同,A随机射,每个数字射中的概率为20分之一。B瞄准某个数字射,但射中的概率只有三分之一,还有另外三分之一射中左右两个。
给出N,求A先射A赢的概率以及B先射B赢的概率。
思路:很容易想出来是概率dp,特殊情况也比较比较好处理。但问题是这里的状态会出现从自身到自身的状态,即dp[i][j]的某一部分是由dp[i][j]推倒而来的,这就形成了一个环。这里有两种解决方法,一是将可能出现环的状态反复迭代做,做上几十次,这样将逐步逼近正确值。比较好写,但运行时间较长。二是把所有环列出,这样将会有许多个等式,然后用高斯消元直接求,速度比较快,但比较难写。
本人采用的是第一种方法,但在poj上不是tle就是wa,实在找不出一个合适的迭代次数,无奈打表。下面给出打表程序。
 /*
* Author: Joshua
* Created Time: 2014年08月23日 星期六 22时20分08秒
* File Name: poj3876.cpp
*/
#include<cstdio>
#define maxn 505
int a[]={,,,,,,,,,,,,,,,,,,,,,};
double dp1[maxn][maxn],dp2[maxn][maxn];
void solve()
{
for (int i=;i<maxn;++i)
{
dp1[][i]=;
dp2[i][]=;
}
for (int i=;i<=;++i)
for (int j=;j<=;++j)
{
for (int t=;t<=;++t)
{
dp1[i][j]=;
for (int k=;k<;++k)
if (i-a[k]>=)
dp1[i][j]+=(-dp2[i-a[k]][j])/20.0;
else
dp1[i][j]+=(-dp2[i][j])/20.0;
dp2[i][j]=;
for (int k=;k<;++k)
{
double temp=;
for (int l=;l<=;++l)
if (j-a[k+l]>=)
temp+=(-dp1[i][j-a[k+l]])/3.0;
else
temp+=(-dp1[i][j])/3.0;
if (temp>dp2[i][j]) dp2[i][j]=temp;
}
if (i> && j>) break;
}
}
}
int main()
{
int n;
solve();
while (scanf("%d",&n) && n)
{
printf("%.12f %.12f\n",dp1[n][n],dp2[n][n]);
} return ;
}

poj3876 darts的更多相关文章

  1. 日本DARTS 支撑的一系列应用项目

    DARTS是多学科空间科学数据平台,例如天体物理.太阳物理.太阳物理.月球与行星科学和微重力科学.在此数据支撑下,有许多应用. 1.http://wms.selene.darts.isas.jaxa. ...

  2. Project Euler 109 :Darts 飞镖

    Darts In the game of darts a player throws three darts at a target board which is split into twenty ...

  3. 4063: [Cerc2012]Darts

    4063: [Cerc2012]Darts Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 85  Solved: 53[Submit][Status] ...

  4. 论文笔记:DARTS: Differentiable Architecture Search

    DARTS: Differentiable Architecture Search 2019-03-19 10:04:26accepted by ICLR 2019 Paper:https://arx ...

  5. 论文笔记系列-DARTS: Differentiable Architecture Search

    Summary 我的理解就是原本节点和节点之间操作是离散的,因为就是从若干个操作中选择某一个,而作者试图使用softmax和relaxation(松弛化)将操作连续化,所以模型结构搜索的任务就转变成了 ...

  6. POJ-1959 Darts

    Darts Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 1286 Accepted: 741 Description Back ...

  7. UVALive 6262 Darts

    Description Consider a game in which darts are thrown at a board. The board is formed by 10 circles ...

  8. DARTS代码分析(Pytorch)

    最近在看DARTS的代码,有一个operations.py的文件,里面是对各类点与点之间操作的方法. OPS = { 'none': lambda C, stride, affine: Zero(st ...

  9. ZOJ3720 Magnet Darts(点在多边形内)

    第一道点在多边形内的判断题,一开始以为是凸的.其实题意很简单的啦,最后转化为判断一个点是否在一个多边形内. 如果只是简单的凸多边形的话,我们可以枚举每条边算下叉积就可以知道某个点是不是在范围内了.但对 ...

随机推荐

  1. 中国剩余定理(CRT)与欧拉函数[数论]

    中国剩余定理 ——!x^n+y^n=z^n 想必大家都听过同余方程这种玩意,但是可能对于中国剩余定理有诸多不解,作为一个MOer&OIer,在此具体说明. 对于同余方程: x≡c1(mod m ...

  2. [luogu P2184] 贪婪大陆 [树状数组][线段树]

    题目背景 面对蚂蚁们的疯狂进攻,小FF的Tower defence宣告失败……人类被蚂蚁们逼到了Greed Island上的一个海湾.现在,小FF的后方是一望无际的大海, 前方是变异了的超级蚂蚁. 小 ...

  3. 关于PHP魔术方法__call的一点小发现

    好久没有上博客园写文章了,今晚终于有点空了,就来写一下昨天的一点小发现. 我自己所知,C++,Java的面向对象都有多态的特点,而PHP没有,但PHP可以通过继承链方法的重写来实现多态的属性.而魔术方 ...

  4. eclipse中console的输出行数控制

    eclipse中console的输出行数控制 开发中,会遇到当输出大量的sql语句或者错误的时候,往往会因为console输出的限制而不能完整显示,所以我们自己就需要迫切的增加显示的行数,这样 就可以 ...

  5. centOS(redhat/oracle linux更换语言

    编辑/etc/sysconfig/i18n将LANG=”zh_CN.UTF-8″ 改为 LANG=”en_US.UTF-8″ 或其他语言中文乱码将LANG=”zh_CN.UTF-8″改为LANG=”z ...

  6. Centos6.5中Nginx部署基于IP的虚拟…

    Centos6.5 中Nginx 部署基于IP 的虚拟主机 王尚2014.11.18 一.介绍虚拟主机 虚拟主机是使用特殊的软硬件技术,把一台真实的物理电脑主机 分割成多个逻辑存储单元,每个单元都没有 ...

  7. 最短路之Bellman-Ford算法

    说明: Dijkstra算法是处理单源最短路径的有效算法,但它局限于边的权值非负的情况,若图中出现权值为负的边,Dijkstra算法就会失效,求出的最短路径就可能是错的. 这时候,就需要使用其他的算法 ...

  8. 贪心:字典树openjudge1799-最短前缀

    描述 一个字符串的前缀是从该字符串的第一个字符起始的一个子串.例如 "carbon"的字串是: "c", "ca", "car&q ...

  9. PXE+kickstart无人值守安装CentOS 6

    本文目录: 1.1 PXE说明 1.2 PXE流程 1.3 部署环境说明 1.4 部署DHCP 1.5 部署TFTP 1.6 提供pxe的bootloader和相关配置文件 1.7 利用原版安装镜像获 ...

  10. sshpass做秘钥分发,ansible做自动化运维工具

    最近公司机器的增多,顺便还要上报表系统,考虑到服务器越来越多,手工的管理显得越来的越吃力,所以打算推进公司自动化运维工具的使用. 推进的过程中,一步一个坑踩过来的.由于公司之前未运用过自动化运维工具, ...