POJ 4014
来源:互联网 发布:域名一般多少钱 编辑:程序博客网 时间:2024/06/05 07:33
ACM ICPC 2011–2012, NEERC, Northern Subregional Contest St Petersburg, October 29, 2011
Problem D. Dice
Input file: dice.in
Output file: dice.out
Time limit: 3 seconds
Memory limit: 256 megabytes
Along with other things, Feadagor is fond of playing tabletop role playing games. He has just discovered a new game and he’d like to play it with his friends. Unluckily, he cannot call his friends right now, as the game requires quite an unusual set of dice. The description of the game says that there must be n dice, and i-th die must have ai faces. Each die must be shaped so its faces fall equiprobably. According to the game manual, the numbers from 1 to m, where m =∑n i=1 ai, must be written on the faces, and each number from the interval must be used exactly once. The numbers arrangement must be chosen so that if you throw all the dice simultaneously, then the mathematical expectation E of the total value in such experiment will be maximal. The manual says that only Maiar have enough wisdom to arrange the numbers properly (and therefore your only choice is to buy the dice just for 133 dollars, telepathy is quite expensive now). But maybe there is a simpler way to make the proper arrangement? Input The first line of the input file contains a single integer number n (1 ≤ n ≤ 1000). The following line contains n integer numbers a1, a2 ... an (1≤ ai ≤100). Output The first line of the output file must contain maximal possible expectation E — a floating-point number precise up to 5 digits after the decimal point. The following n lines must contain the numbers arrangement: i-th line must contain ai integer numbers — the numbers to be written on the faces of i-th die. Exampledice.in dice.out
2 1 4
7.50000 5 1 2 3 4
大水题,贪心~~
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;struct A{ int num; int c; int b[105];}a[1005];bool cmp1(A a,A b){ return a.c < b.c;}bool cmp2(A a,A b){ return a.num < b.num;}int main(){ int n; double ans; while(scanf("%d",&n) != EOF) { int sum = 0; ans = 0.0; for(int i = 1;i<= n;i ++) { scanf("%d",&a[i].c); sum += a[i].c; a[i].num = i; } sort(a+1,a+1+n,cmp1); for(int i = 1;i <=n ;i++) { for(int j = 1;j <= a[i].c;j ++) { a[i].b[j] = sum; ans += 1.0/a[i].c*sum; sum--; } } sort(a+1,a+1+n,cmp2); printf("%.5lf\n",ans); for(int i = 1;i <= n;i ++) { for(int j = a[i].c;j >1;j--) printf("%d ",a[i].b[j]); printf("%d\n",a[i].b[1]); } } return 0;}
0 0
- POJ 4014
- POJ 4014
- poj 4014 Dice 贪心
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- uva 1614Hell on the Markets
- 计算mysql内存使用
- extjs 在toolbar中加入文本框 下拉框
- ACM经典算法之数据结构
- MSP430G2553与MSP430F5336系列单片机总结[0]——概述
- POJ 4014
- 先尝试后决策
- 多点加锁实现负载均衡机制
- 类的继承
- cocos2d-x 3.6运行cocos run出现Ndk build failed解决办法
- Win7*64+androidstudio ndk-build.cmd finished with non-zero exit value 1 问题原因
- 工程文件目录及程序的启动原理
- 慕课玩儿转swift笔记02-字符串
- 生成5位序列号