URAL 1735 Theft of the Century

題意

有兩種物品:白金和金子,單位重量分別爲x,y ,裝在n 個袋子裏,每個袋子裏物品種類相同,並且分別有m 個。
現在要從每個袋子中拿出一些,一起稱重,只能稱一次,問是否一定能知道每個袋子裏物品的種類是什麼,如果可以,並輸出方案。

題解

題目給定x<y 。那麼,事實上,稱一次重,可能有2n 種狀態。
那麼,原題轉化爲:
要求一個集合Sf(S) 定義爲S 中元素的和,則有S 的冪集所有sf(s) 互不相同,問min{max(x|xS)}
可以在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;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章