Play the Dice

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)

Total Submission(s): 1328    Accepted Submission(s): 429

Special Judge

Problem 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 ai(0<=ai<200)

The second line is an integer m (0<=m<=n), following with m integers bi(1<=bi<=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
 

思路:刚開始理解错题意了,老感觉那m个面的数字的大小和结果有关。

事实上,掷到一个特殊面仅仅是得到了一个再次投掷的机会,和第一次投掷的效果全然一样。

sum=a1+a2+...+an; a=sum/n;  q=m/n;

ans=a+a*q+a*q^2+...=sum/(n-m);

#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
#define N 205
const int inf=0x3fffffff;
int a[N];
int main()
{
int i,n,m,t;
double sum;
while(scanf("%d",&n)!=-1)
{
sum=0;
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
scanf("%d",&m);
for(i=0;i<m;i++)
{
scanf("%d",&t);
}
if(sum==0)
{
printf("0.00\n");
continue;
}
if(m==n)
{
printf("inf\n");
continue;
}
printf("%.2f\n",sum/(n-m));
}
return 0;
}

最新文章

  1. [BS-26] UIView、pop和Core Animation区别
  2. 放松时刻——C#分割字符串
  3. C#委托详解(3):委托的实现方式大全(续)
  4. 判断webpart类型 How can I tell what type a web part is?
  5. js replace如何实现全部替换
  6. redis 学习笔记一
  7. 2016年团体程序设计天梯赛-决赛 L1-8. Left-pad(20)
  8. Django中Admin样式定制
  9. U-boot-1.1.4中关于hello_world.srec出错
  10. 三、自动化测试平台搭建-django-如何用mysql数据库做web项目
  11. (转)Python中操作mysql的pymysql模块详解
  12. visual studio 2008 快捷键
  13. [转]MAC:删除终端默认前缀的计算机名
  14. 毕向东_Java基础视频教程第20天_IO流(15~17)
  15. Delphi Android USB Interface with the G2
  16. Hibernate学习笔记四
  17. WinForm的Chart图形控件
  18. CSS 笔记之 CSS 选择器
  19. &lt;正则吃饺子&gt;:关于java中对内存部分的简单总结整理
  20. [Angular Directive] Structure directive and &lt;template&gt;

热门文章

  1. css定位、position与float同时使用的情况
  2. golang——(strings包)常用字符串操作函数
  3. Kettle环境变量配置
  4. Win10切换JDK版本
  5. 复习HTML+CSS(9)
  6. jQuery学习笔记之插件开发(4)
  7. for 循环练习题(2)
  8. AMQP及RabbitMQ
  9. chown chmod chgrp chattr chroot usermod 命令简单分析
  10. jq 获取表单所有数据