POJ 4014

3 篇文章 0 订阅

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. Example
dice.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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值