周赛

题目描述

A friend of yours is working on an AI program to play backgammon, and she has a small problem. At
the end of the game, each player’s 15 pieces are moved onto a set of 6 board positions called points, numbered 1 through 6. The pieces can be distributed in any manner across these points: all 15 could
be on point 3; 5 could be on point 6, 2 on point 5, 3 on point 4 and 5 on point 2; etc. Your friend
wants to store all these possible configurations (of which there are 15504) into a linear array, but she needs a mapping from configuration to array location. It seems logical that the configuration with all 15
pieces on point 1 should correspond to array location 0, and the configuration of all 15 pieces on point 6 should correspond to the last array location. It’s the ones in between that are giving her problems.
That’s why she has come to you.
You decide to specify a configuration by listing the number of pieces on each point, starting with
point 6. For example, the two configurations described above could be represented by (0, 0, 0, 15, 0, 0) and (5, 2, 3, 0, 5, 0). Then you can order the configurations in lexicographic ordering, starting with (0,0,0,0,0,15), then (0, 0, 0, 0, 1, 14), (0, 0, 0, 0, 2, 13), . . . , (0, 0, 0, 0, 14, 1), (0, 0, 0, 0, 15, 0), (0, 0, 0, 1, 0, 14), (0, 0, 0, 1, 1, 13), etc., ending with (15, 0, 0, 0, 0, 0). Now all you need is a way to map these orderings to array indices. Literally, that’s all you need, because that’s what this problem is all about.

输入

Each test case will consist of one line, starting with a single character, either ‘m’ or ‘u’. If it is an ‘m’
it will be followed by a configuration and you must determine what array index it gets mapped to. If
it is a ‘u’ then it will be followed by an integer array index i, 0 ≤ i < 15504, and you must determine what configuration gets mapped to it. A line containing the single character ‘e’ will end input.

输出

For each test case, output the requested answer – either an array index or a configuration. Follow the format in the examples below.

示例输入

m 0 0 0 0 0 15
u 15503
e

示例输出

Case 1: 0
Case 2: 15 0 0 0 0 0

提示

#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int num[15555][7];
int sum;
void start()
{
    sum=0;
    for(int i=0; i<=15; i++)
        for(int j=0; j<=15; j++)
            for(int h=0; h<=15; h++)
                for(int g=0; g<=15; g++)
                    for(int k=0; k<=15; k++)
                        for(int m=0; m<=15; m++)
                        {
                            if(i+j+h+g+k+m==15)
                            {
                                num[sum][0]=i;
                                num[sum][1]=j;
                                num[sum][2]=h;
                                num[sum][3]=g;
                                num[sum][4]=k;
                                num[sum++][5]=m;
                            }
                        }
}
int main()
{
    start();
    char op;
    int a,b,c,d,e,f;
    int ss=1;
    while(cin>>op)
    {
        if(op=='e')
         break;
        if(op=='m')
        {
            scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
            for(int i=0;i<sum;i++)
            if(num[i][0]==a&&num[i][1]==b&&num[i][2]==c&&num[i][3]==d&&num[i][4]==e&&num[i][5]==f)
            {
                printf("Case %d: %d\n",ss,i);
                break;
            }
        }
        else
        {
            scanf("%d",&a);
            printf("Case %d: %d %d %d %d %d %d\n",ss,num[a][0],num[a][1],num[a][2],num[a][3],num[a][4],num[a][5]);
        }
        ss++;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值