Mancala II

题目描述

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



 

 

 1 #pragma GCC optimize("Ofast,no-stack-protector")
 2 #pragma GCC optimize("O3")
 3 #pragma GCC optimize(2)
 4 #include <bits/stdc++.h>
 5 #define inf 0x3f3f3f3f
 6 #define linf 0x3f3f3f3f3f3f3f3fll
 7 #define pi acos(-1.0)
 8 #define nl "\n"
 9 #define pii pair<ll,ll>
10 #define ms(a,b) memset(a,b,sizeof(a))
11 #define FAST_IO ios::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL)
12 using namespace std;
13 typedef long long ll;
14 const int mod = 998244353;
15 ll qpow(ll x, ll y){ll s=1;while(y){if(y&1)s=s*x%mod;x=x*x%mod;y>>=1;}return s;}
16 //ll qpow(ll a, ll b){ll s=1;while(b>0){if(b%2==1)s=s*a;a=a*a;b=b>>1;}return s;}
17 inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();return x*f;}
18  
19 const int N = 1e5+5;
20  
21 int a[N];
22  
23 int main()
24 {
25     int _, cas, n;
26     for(scanf("%d",&_);_--;)
27     {
28         scanf("%d%d",&cas,&n);
29         printf("%d ",cas);
30         ms(a, 0);
31         int mx = 0;
32         while(n--)for(int j=1;;j++){
33             if(!a[j]){
34                  a[j] = j; mx = max(mx,j);
35                  break;
36             }
37             a[j]--;
38         }
39  
40         printf("%d\n",mx);
41         for(int i=1;i<=mx;i++){
42             if(i%10!=1) printf(" ");
43             printf("%d",a[i]);
44             if(i%10==0 || i==mx) printf("\n");
45         }
46  
47     }
48     return 0;
49 }

 

posted @ 2019-08-21 10:15  Osea  阅读(236)  评论(0编辑  收藏  举报