题目描述

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

 #pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("O3")
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
#define pi acos(-1.0)
#define nl "\n"
#define pii pair<ll,ll>
#define ms(a,b) memset(a,b,sizeof(a))
#define FAST_IO ios::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef long long ll;
const int mod = ;
ll qpow(ll x, ll y){ll s=;while(y){if(y&)s=s*x%mod;x=x*x%mod;y>>=;}return s;}
//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;}
inline int read(){int x=,f=;char ch=getchar();while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}while(ch>=''&&ch<='') x=x*+ch-'',ch=getchar();return x*f;} const int N = 1e5+; int a[N]; int main()
{
int _, cas, n;
for(scanf("%d",&_);_--;)
{
scanf("%d%d",&cas,&n);
printf("%d ",cas);
ms(a, );
int mx = ;
while(n--)for(int j=;;j++){
if(!a[j]){
a[j] = j; mx = max(mx,j);
break;
}
a[j]--;
} printf("%d\n",mx);
for(int i=;i<=mx;i++){
if(i%!=) printf(" ");
printf("%d",a[i]);
if(i%== || i==mx) printf("\n");
} }
return ;
}

最新文章

  1. crontab 提示 command not found 解决方案
  2. Mssql中一些常用数据类型的说明和区别
  3. Java 集合系列14之 Map总结(HashMap, Hashtable, TreeMap, WeakHashMap等使用场景)
  4. 自己写方法处理WP(RT)后退键事件处理
  5. 谈Objective-C Block的实现
  6. C# 保留2位小数
  7. 基于协同过滤的个性化Web推荐
  8. Js打开网页后居中显示
  9. 修改UISearchBar placeholder textColor
  10. 小米手机与魅族的PK战结果 说明了什么
  11. xmanager 使用
  12. jquery判断对象的type
  13. php处理表单中的复选框问题以及js实现全选
  14. openssl私钥转换为PKCS8
  15. pycharm中字体大小的调整方法
  16. Sketch 画原型比 Axure 好用吗?为什么?
  17. C++学习3--编程基础(vector、string、三种传参)
  18. 【代码笔记】iOS-动画的跳转
  19. scp ssh: connect to host 9.123.159.41 port 22:connection refused的解决办法
  20. 怎样编写YARN应用程序

热门文章

  1. codeforces gym #101161E - ACM Tax(lca+主席树)
  2. root of context hierarchy
  3. Raspberry Pi 4B 使用OpenCV访问摄像头picamera模块
  4. 【git 命令总结】一
  5. chrome jssip
  6. vue不同序号的元素添加不同的样式
  7. Qt pro工程文件介绍
  8. API网关的用处
  9. kotlin中对象表达式
  10. 001-jdk-数据结构-总览