题解 | #称砝码#

称砝码

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

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        List<Integer> list = new ArrayList<>();
        Set<Integer> set = new HashSet<>();
        set.add(0);
        while (--n >= 0) {
            list.add(in.nextInt());
        }
        for (int i = 0; i < list.size(); i++) {
            int x = in.nextInt();
            List<Integer> temp = new ArrayList<>();
            for (Integer it : set) {
                for (int j = 0; j <= x; j++) {
                    temp.add(it + list.get(i) * j);
                }
            }
            set.addAll(temp);
        }
        System.out.println(set.size());

    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
08-01 16:13
点赞 评论 收藏
分享
07-09 20:50
门头沟学院 Java
码农索隆:1.教育背景和荣誉证书合二为一。 2.获奖项目理一遍,你做了什么,对你求职的岗位有什么帮助,没有就删掉。 3.技能特长和教育背景交换位置。 4.技能特长写的太差,上网上找简历参考。都不用问你别的,一个redis就能把你问住,写写你具体会redis哪些方面的知识。
点赞 评论 收藏
分享
07-29 14:49
门头沟学院 Java
ResourceUt...:浙大✌️吉祥
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务