A - Play the Dice
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87326#problem/A

Description

There is a dice with n sides, which are numbered from 1,2,...,n and have the equal possibility to show up when one rolls a dice. Each side has an integer ai on it. Now here is a game that you can roll this dice once, if the i-th side is up, you will get ai yuan. What's more, some sids of this dice are colored with a special different color. If you turn this side up, you will get once more chance to roll the dice. When you roll the dice for the second time, you still have the opportunity to win money and rolling chance. Now you need to calculate the expectations of money that we get after playing the game once.

Input

Input consists of multiple cases. Each case includes two lines. 
The first line is an integer n (2<=n<=200), following with n integers a i(0<=a i<200) 
The second line is an integer m (0<=m<=n), following with m integers b i(1<=b i<=n), which are the numbers of the special sides to get another more chance.

Output

Just a real number which is the expectations of the money one can get, rounded to exact two digits. If you can get unlimited money, print inf.

Sample Input

6 1 2 3 4 5 6
0
4 0 0 0 0
1 3

Sample Output

3.50
0.00

HINT

题意

一个n面的骰子,每一面有分值,并且扔到某些面的时候,可以再扔一次,然后问你最后得分的期望是多少

题解

  设期望值为s,前m个是再来一次机会,则有

  s=(a[1]+s)/n+(a[2]+s)/n+……+(a[m]+s)/n+a[m+1]/n……

   化简:(n-m)s=sum

   当sum=0时,为0;

    当n==m时,为inf;

    否则为sum/(n-m).

代码:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <typeinfo>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//*************************** int main()
{
int n;
int hh;
while(cin>>n)
{
double sum=;
double a[];
for(int i=;i<=n;i++)
{
a[i]=read();
sum+=a[i];
}
int m;
cin>>m;
for(int i=;i<=m;i++)
{
hh=read();
}
if(sum==)cout<<<<endl;
else
if(n==m)cout<<"inf"<<endl;
else
printf("%.2f\n",sum/(n-m));
}
return ;
}

最新文章

  1. Intent(二)隐式调用intent
  2. 【BZOJ-4590】自动刷题机 二分 + 判定
  3. ASP.NET MVC4 &amp; Entity Framework 6.0 IIS 部署出错解决方案
  4. Mac快捷键 Xcode快捷键
  5. MongoDB(2):入门
  6. Java Lock
  7. Web打印控件smsx.cab使用说明
  8. windows linux—unix 跨平台通信集成控制系统----文件搜索
  9. python list用法
  10. 大数据入门到精通12--spark dataframe 注册成hive 的临时表
  11. 同步或者重构Activiti Identify用户数据的多种方案比较
  12. .3-浅析express源码之applicaiton模块(2)-app.render
  13. 使用 numpy.random.choice随机采样
  14. 初学Struts2
  15. iOS - 代码规范的提示
  16. linux中创建一个回收站
  17. 032-IDUtils 工具类模板
  18. 【ANSIBLE】ansible控制windows插件安装及运行error与解决方法
  19. HTML 参考手册- (HTML5 标准)
  20. mac下finder子目录直接打开终端

热门文章

  1. linux 优化&amp;安全运维&amp;黑客攻防
  2. yum使用本地源
  3. 安卓(Android)手机如何安装APK?
  4. 支付宝微信O2O大战,WiFi广告在夹缝中求生存
  5. Android 云服务器的搭建和友盟APP自动更新功能的实现
  6. 一步步实现Nagios监控linux主机及飞信报警
  7. 使用pymongo需要手动关闭MongoDB Connection吗?
  8. ORM框架是什么
  9. Eclipse 项目红色叹号:Build Path Problem
  10. Solr5.3.1 SolrJ查询索引结果