題意
有兩種物品:白金和金子,單位重量分別爲
現在要從每個袋子中拿出一些,一起稱重,只能稱一次,問是否一定能知道每個袋子裏物品的種類是什麼,如果可以,並輸出方案。
題解
題目給定
那麼,原題轉化爲:
要求一個集合
可以在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;
}