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(点在多边形内)
第一道点在多边形内的判断题,一开始以为是凸的.其实题意很简单的啦,最后转化为判断一个点是否在一个多边形内. 如果只是简单的凸多边形的话,我们可以枚举每条边算下叉积就可以知道某个点是不是在范围内了.但对 ...
随机推荐
- Jmeter使用代理服务器录制脚本
Mark一下Jmeter使用代理服务器录制脚本,以备自己可以翻阅,也可以帮助其他人了解一下Jmeter的这个功能.其实录制脚本只是在我们工作中的一个小插曲而已,只是为了能快速看到应用程序跑的逻辑及实现 ...
- python函数(2):函数进阶
昨天说了函数的一些最基本的定义,今天我们继续研究函数.今天主要研究的是函数的命名空间.作用域.函数名的本质.闭包等等 预习: 1.写函数,用户传入修改的文件名,与要修改的内容,执行函数,完成整个文件的 ...
- 使用pdfbox分页保存pdf为图片
一.背景 pdfbox作为Apache开源的PDF操作工具,允许创建新的PDF文档,操作现有文档,以及从文档中提取内容的能力.Apache PDFBox还包括一些命令行实用工具.本文楼主主要介绍其中的 ...
- 移动端和pc端事件绑定方式以及取消浏览器默认样式和取消冒泡
### 两种绑定方式 (DOM0)1.obj.onclick = fn; (DOM2)2. ie:obj.attachEvent(事件名称,事件函数); 1.没有捕获(非标准的ie 标准的ie底下有 ...
- python函数(4):递归函数及二分查找算法
人理解循环,神理解递归! 一.递归的定义 def story(): s = """ 从前有个山,山里有座庙,庙里老和尚讲故事, 讲的什么呢? ""& ...
- Tornado-StaticFileHandler参考
StaticFileHandler ====== tornado.web.StaticFileHandler 源代码中的解释 class StaticFileHandler(RequestHandle ...
- Qt For Android 开发环境配置
想了想,还是再写一篇关于Qt for Android开发环境配置的教程. 准备:Java jdk,Android sdk,Android adb,Android ndk,Android ant,Qt ...
- wamp本地安装phpwind问题:‘Rewrit…
一.问题出现的现象: 1.http://localhost/phpwind_v9.0_utf8/upload/install.php显示. 2.apache错误文件httpd.conf显示: .hta ...
- echarts 支持svg格式
今天研究了下echarts的svg格式.发现用ai生成svg格式的图片,echarts上面显示不了. 经过了多次的百度和谷歌终于找到了用Method Draw画出来的svg格式,echarts就能加载 ...
- c++ STL 容器——联合容器
STL提供了四种联合容器 set,multiset,map,multimap; set and multiset在<set>头文件 map and multimap在<map> ...