题解 | #称砝码#

称砝码

https://www.nowcoder.com/practice/f9a4c19050fc477e9e27eb75f3bfd49c

num = input('');
wei_num = [];
for ii = 1 : 2
    line = input('', 's');
    lines = strsplit(line,' ');
    for jj = 1 : num
        d11 = lines{jj};
        wei_num(ii,jj) = str2num(d11);
    end
end
num_now = [];
for jj = 1 : size(wei_num,2) 
   num_now =[num_now;repmat(wei_num(1,jj),wei_num(2,jj),1)];
end
out_end = [0];
%%% 重复的类型
for ii = 1 : length(num_now)
    out_now = out_end + num_now(ii);
    out_end = [out_end out_now];   
    out_end = unique(out_end); 
end
printf("%d\n",length(out_end));

全部评论

相关推荐

喜欢走神的孤勇者练习时长两年半:爱华,信华,等华,黑华
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务