Mancala

题目描述
Mancala is a family of board games played around the world, sometimes called sowing games, or count-and-capture games, which describes the game play. One simple variant is a solitaire game called Tchoukaillon which was described by Véronique Gautheron. Tchoukaillon is played on a board with an arbitrary number of bins numbered 1, 2, …, containing b[1], b[2], …, counters respectively and an extra empty bin called the Roumba on the left.

在这里插入图片描述

A single play consists on choosing a bin, n, for which b[n] = n (indicated by the darker circles in the diagram) and distributing the counters one per bin to the bins to the left including the Roumba (getting the next diagram below in the fi gure above). If there is no bin where b[n] = n, then the board
is a losing board.
If there is a sequence of plays which takes the initial board distribution to one in which every counter is in the Roumba, the initial distribution is called a winnable board. In the example above, 0, 1, 3, …is a winnable board (the “…” indicates all the bins to the right of bin 3 contain 0). For each total number of counters, there is a unique distribution of the counters to bins to make a winnable board for that total count (so 0, 1, 3, …is the only winnable board with 4 counters).
Write a program which fi nds the winnable board for a total count input.

输入
The first line of input contains a single integer P, (1 ≤ P ≤ 1000), which is the number of data sets that follow. Each data set should be processed identically and independently.
Each data set consists of a single line of input. It contains the data set number, K, followed by a single space, followed by the total count N (1 ≤ N ≤ 2000) of the winnable board to be found.

输出
For each data set there will be multiple lines of output. The first line of output contains the data set number, K, followed by a single space, followed by the index of the last bin, B, with a non-zero count.
Input will be chosen so that B will be no more than 80. The first line of output for each dataset is followed by the bin counts b[1], b[2], …, b[B], 10 per line separated by single spaces.

样例输入
3
1 4
2 57
3 500

样例输出
1 3
0 1 3
2 12
1 2 2 2 2 6 2 4 6 8
10 12
3 39
0 2 2 1 3 2 2 2 6 7
5 0 6 12 2 6 10 14 18 1
3 5 7 9 11 13 15 17 19 21
23 25 27 29 31 33 35 37 39

思路
因为n,q,b的数据范围较小,且每一位的总数不会超过该位位下标数,所以暴力枚举最高位即可

代码实现

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N=100;

int line[N];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        memset(line,0,sizeof(line));
        int id,b,maxl=0;
        scanf("%d%d",&id,&b);
        while(b)
        {
            int len=1;
            while(len)
            {
                if(!line[len]) break;
                else len++;
            }
            maxl=max(maxl,len);
            b--;
            line[len]+=len;
            for(int j=1;j<len;j++) line[j]--;
        }
        printf("%d %d\n",id,maxl);
        for(int i=1;i<=maxl;i++)
        {
            printf("%d",line[i]);
            if(i%10==0) puts("");
            else printf(" ");
        }
        if(maxl%10) puts("");
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值