URAL 1735 Theft of the Century

探讨了通过称重判断袋内物品种类的问题,利用Conway-Guy序列找到最小正整数集合,确保所有子集的和各不相同。代码实现采用C++。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题意

有两种物品:白金和金子,单位重量分别为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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值