题意
有两种物品:白金和金子,单位重量分别为
x,y
,装在
n
个袋子里,每个袋子里物品种类相同,并且分别有
现在要从每个袋子中拿出一些,一起称重,只能称一次,问是否一定能知道每个袋子里物品的种类是什么,如果可以,并输出方案。
题解
题目给定
x<y
。那么,事实上,称一次重,可能有
2n
种状态。
那么,原题转化为:
要求一个集合
S
,
可以在oeis上搜索Conway-Guy sequence。。。
Conway-Guy sequence: a(n + 1) = 2a(n) - a(n - floor( 1/2 + sqrt(2n) ))
Conway and Guy conjecture that the set of k numbers {s_i = a(k) - a(k-i) : 1 <= i <= k} has the property that all its subsets have distinct sums - see Guy’s book.
0, 1, 2, 4, 7, 13, 24, 44…
Triangle read by rows in which row n gives the n-set obtained as the differences {b(n)-b(n-i), 0 <= i <= n-1}, where b() = A005318().
{1}
{1,2}
{2,3,4}
{3,5,6,7}
{6,9,11,12,13}
{11,17,20,22,23,24}
…
。。。
恩,就是这样,这是一道数学题。。。
code
#include<cstdio>
#include<cmath>
const int maxn=100;
int n,k,x,y;
int a[maxn];
int main(){
a[1]=1;
for(int i=2;i<maxn;++i) a[i]=2*a[i-1]-a[(i-1)-(int)(0.5+sqrt(2*(i-1)))];
scanf("%d%d%d%d",&n,&k,&x,&y);
if (k<a[n]){ puts("NO"); return 0; }
puts("YES");
for(int i=1;i<=n;++i){
printf("%d ",a[n]-a[n-i]);
}
// for(;;);
return 0;
}