题目描述

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 ;
}

Mancala II的更多相关文章

  1. Leetcode 笔记 113 - Path Sum II

    题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...

  2. Leetcode 笔记 117 - Populating Next Right Pointers in Each Node II

    题目链接:Populating Next Right Pointers in Each Node II | LeetCode OJ Follow up for problem "Popula ...

  3. 函数式Android编程(II):Kotlin语言的集合操作

    原文标题:Functional Android (II): Collection operations in Kotlin 原文链接:http://antonioleiva.com/collectio ...

  4. 统计分析中Type I Error与Type II Error的区别

    统计分析中Type I Error与Type II Error的区别 在统计分析中,经常提到Type I Error和Type II Error.他们的基本概念是什么?有什么区别? 下面的表格显示 b ...

  5. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  6. [LeetCode] Guess Number Higher or Lower II 猜数字大小之二

    We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to gues ...

  7. [LeetCode] Number of Islands II 岛屿的数量之二

    A 2d grid map of m rows and n columns is initially filled with water. We may perform an addLand oper ...

  8. [LeetCode] Palindrome Permutation II 回文全排列之二

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

  9. [LeetCode] Permutations II 全排列之二

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

随机推荐

  1. 注解之 @RestController 和 @RequestMapping

    Controller 是 Spring 中最基本的组件,主要处理用户交互,一般每个业务逻辑都会有一个 Controller,供用户请求接口进行数据访问:@RequestMapping 注解用于绑定UR ...

  2. Robot Framework(十七) 扩展RobotFramework框架——扩展Robot Framework Jar

    4.4扩展Robot Framework Jar 使用标准JDK安装中包含的jar命令,可以非常简单地向Robot Framework jar添加其他测试库或支持代码.Python代码必须放在jar里 ...

  3. Java排序之计数排序

    Java排序之计数排序 计数排序思路 计数排序适用于有明确范围的数组,比如给定一个数组,且知道所有值得范围是[m,n].这个时候可以使用一个n-m+1长度的数组,待排序的数组就可以散在这个数组上,数组 ...

  4. 在SQLAlchemy ORM中动态变更表名

    在开发过程中,经常会遇到几张表结构相同,仅仅表名不一样.这在直接使用SQL语句进行查询的环境中处理起来很简单,但如果使用了SQLAlchemy ORM之后,因在model定义时就确定了表名,就需要用其 ...

  5. Python 自学笔记(二)

    3-1.条件判断 3-1.条件判断 3-1-1.单项判断 if 3-1-2.双向判断 if...else... 3-1-3.多向判断 if...elif...else 3-2.if嵌套 4.输入 4- ...

  6. django 后台静态文件不显示

    原文链接 https://my.oschina.net/VASKS/blog/874270 django admin svg 不显示.后台显示 xx.svg 200 但浏览器就是不显示. 百度了一圈, ...

  7. 使用express-session实现登录效果

    本文为后端练兵内容,重复造轮子,重复造轮子才能有经验,才能生出花来. 本次练兵,采用的是数据库保存账户密码,后端通过查数据库的方式,实现账号和密码的校验. 如果验证成功,将登陆状态保存在session ...

  8. java工厂模式的测试

    /** * 工厂模式的测试 * <p> * 工厂方法模式 * 工厂方法模式是简单工厂模式的进一步抽象化和推广,工厂方法模式里不再只由一个工厂类决定那一个产品类应当被实例化,这个决定被交给抽 ...

  9. 图像质量评价-NQM和WPSNR

    王保全. 基于混合专家模型的快速图像超分辨率方法研究与实现[D]. 2015. PSNR 和SSIM 在有时候并不能很确切的表示图像质量 标准,该论文中根据一定量的人为的感知评分作为参考,用斯皮尔曼等 ...

  10. OS X以及iOS中与硬件环境相关的预定义宏

    由于现在ARM处理器的飞速发展,从Apple A4到现在的Apple A7,从32位到64位,每一代处理器几乎都增加了不少特性,从而在架构上也有所不同.比如Apple A6引入了ARMv7S架构,增加 ...