poj3876 darts
| Time Limit: 1000MS | Memory Limit: 65536K | |||
| Total Submissions: 58 | Accepted: 32 | Special Judge | ||
Description
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
Output
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的更多相关文章
- 日本DARTS 支撑的一系列应用项目
DARTS是多学科空间科学数据平台,例如天体物理.太阳物理.太阳物理.月球与行星科学和微重力科学.在此数据支撑下,有许多应用. 1.http://wms.selene.darts.isas.jaxa. ...
- Project Euler 109 :Darts 飞镖
Darts In the game of darts a player throws three darts at a target board which is split into twenty ...
- 4063: [Cerc2012]Darts
4063: [Cerc2012]Darts Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 85 Solved: 53[Submit][Status] ...
- 论文笔记:DARTS: Differentiable Architecture Search
DARTS: Differentiable Architecture Search 2019-03-19 10:04:26accepted by ICLR 2019 Paper:https://arx ...
- 论文笔记系列-DARTS: Differentiable Architecture Search
Summary 我的理解就是原本节点和节点之间操作是离散的,因为就是从若干个操作中选择某一个,而作者试图使用softmax和relaxation(松弛化)将操作连续化,所以模型结构搜索的任务就转变成了 ...
- POJ-1959 Darts
Darts Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 1286 Accepted: 741 Description Back ...
- UVALive 6262 Darts
Description Consider a game in which darts are thrown at a board. The board is formed by 10 circles ...
- DARTS代码分析(Pytorch)
最近在看DARTS的代码,有一个operations.py的文件,里面是对各类点与点之间操作的方法. OPS = { 'none': lambda C, stride, affine: Zero(st ...
- ZOJ3720 Magnet Darts(点在多边形内)
第一道点在多边形内的判断题,一开始以为是凸的.其实题意很简单的啦,最后转化为判断一个点是否在一个多边形内. 如果只是简单的凸多边形的话,我们可以枚举每条边算下叉积就可以知道某个点是不是在范围内了.但对 ...
随机推荐
- Ajax获取服务器信息
xhr.onreadystatechange = function(){ if (xhr.readyState == 4){ if ((xhr.status >= 200 && ...
- 配置LAMP实现WordPress
环境说明: 在同一台主机上实现LAMP(Linux + Apache + MariaDB + PHP) CentOS 7.3.Apache 2.4.6.MariaDB 5.5.52.PHP 5.4.1 ...
- JavaScript关于js垃圾回收
js中会自动回收那些我们不使用的变量 一般回收算法用的是一个回收器, 这个回收器周期性的遍历程序运行中的所有变量, 并且给这些变量所引用的值做上一个标记, 如果被引用的值是一个对象或是一个数组, 那么 ...
- 最短路之Floyd算法
1.介绍 floyd算法只有五行代码,代码简单,三个for循环就可以解决问题,所以它的时间复杂度为O(n^3),可以求多源最短路问题. 2.思想: Floyd算法的基本思想如下:从任意节点A到任意节点 ...
- 5.npm scripts 使用指南
简单介绍 scripts里面的 "start": "node app" npm run start 相当于 node app { "name" ...
- 解决 apache poi 转换 word(docx) 文件到 html 文件表格没边框的问题
一.起因 这几天在做电子签章问题,要通过替换docx文件中的占位符生成包含业务数据的合同数据,再转换成html文件,转换成pdf文件.遇到的问题是:通过apache poi转换docx到html时,原 ...
- nopcommerce的WidgetZones
来自:http://www.kingreatwill.com Hi, Having just started developing nopCommerce (and having forked out ...
- akoj-1059-Picture
Description 给你一个矩形的宽度和高度,要求按sample output样例输出此矩形. Input 输入包含多组数据,每一组包含两个数N和M( 0 < N ,M , < 75 ...
- MySQL grant命令使用
MySQL 赋予用户权限命令的简单格式可概括为: grant 权限 on 数据库对象 to 用户 一.grant 普通数据用户,查询.插入.更新.删除 数据库中所有表数据的权利. grant sele ...
- ReactiveSwift源码解析(十一) Atomic的代码实现以及其中的Defer延迟、Posix互斥锁、递归锁
本篇博客我们来聊一下ReactiveSwift中的原子性操作,在此内容上我们简单的聊一下Posix互斥锁以及递归锁的概念以及使用场景.然后再聊一下Atomic的代码实现.Atomic主要负责多线程下的 ...