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