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. 平方根的C语言实现(一)

    曾经做一个硬件成本极度控制的项目,因为硬件成本极低,并且还需要实现较高的精度测量,过程中也自己用C语言实现了正弦.余弦.反正切.平方根等函数. 以下,无论是在我的实际项目中还是本地的计算机系统,int ...

  2. 移动端和pc端事件绑定方式以及取消浏览器默认样式和取消冒泡

    ### 两种绑定方式 (DOM0)1.obj.onclick = fn; (DOM2)2. ie:obj.attachEvent(事件名称,事件函数); 1.没有捕获(非标准的ie 标准的ie底下有 ...

  3. ubuntu下使用 chkconfig 是一种习惯

    ubuntu下使用 chkconfig 是一种习惯 习惯了chkconfig命令, 闲来写了个脚本模拟下, 步骤很简单. 如下: 第一步, 安装sysv-rc-conf sudo apt instal ...

  4. JSON风格指南

    中文版:https://github.com/darcyliu/google-styleguide/blob/master/JSONStyleGuide.md 英文版:https://google.g ...

  5. Android 性能测试——Heap Viewer 工具

    Android 性能测试--Heap Viewer 工具 Heap Viewer能做什么? 实时查看App分配的内存大小和空闲内存大小 发现Memory Leaks Heap Viewer使用条件 5 ...

  6. Java curator操作zookeeper获取kafka

    Java curator操作zookeeper获取kafka Curator是Netflix公司开源的一个Zookeeper客户端,与Zookeeper提供的原生客户端相比,Curator的抽象层次更 ...

  7. [NOIP 2011]聪明的质监员

    聪明的质监员 题目 小 T 是一名质量监督员,最近负责检验一批矿产的质量.这批矿产共有n个矿石,从 1 到n逐一编号,每个矿石都有自己的重量wi以及价值vi.检验矿产的流程是: 1. 给定 m个区间[ ...

  8. vue指令v-text示例解析

    <div id="app"> <!--两种方式都是插值,输出结果一样--> <p v-text="msg"></p&g ...

  9. MySQL开发指南

    数据库开发是数据库管理系统(DBMS)和数据库应用软件设计研发的总称,数据运维.参与数据库生产环境的问题优化和解决等方面的事宜. 1.关于MySQL数据库 2.搭建MySQL环境 3.入门常用SQL. ...

  10. 福科田led漫反射灯条生产工序

    led漫反射灯条简称透镜灯条,它两个其实是一种产品.下面我来讲讲led漫反射灯条的生产工序.首先介绍的是led漫反射灯条的生产总流程. 一.      led漫反射灯条的生产总流程: 1.       ...