竞赛讨论区 > 在线帮忙找bug
头像
yeshichen
发布于 2021-01-06 21:33
+ 关注

在线帮忙找bug

public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int[] arr=new int[scan.nextInt()];
        scan.nextLine();
        for(int i=0;i<arr.length;i++)
            arr[i]=scan.nextInt();
        int[] solution=new int[scan.nextInt()];
        scan.nextLine();
        for(int i=0;i<solution.length;i++){
            solution[i]=scan.nextInt();
            scan.nextLine();
        }
        boolean[] res=new boolean[solution.length];
        Set<Integer> set=new HashSet();
        set.add(0);
        for(int i=0;i<arr.length;i++){
            Iterator<Integer> iterator=set.iterator();
            Set<Integer> tmp=new HashSet();
            while(iterator.hasNext())
                tmp.add(iterator.next()+arr[i]);
            set.addAll(tmp);
        }
        for(int i=0;i<solution.length;i++){
            if(solution[i]>10000){
                System.out.println("NO");
                continue;
            }
            Iterator<Integer> iterator=set.iterator();
            boolean flag=false;
            while(iterator.hasNext()){
                int val=iterator.next();
                if(set.contains(val-solution[i])){
                    flag=true;
                    break;
                }
            }
            System.out.println(flag?"YES":"NO");
        }
    }

全部评论

(1) 回帖
加载中...
话题 回帖

本文相关内容

等你来战

查看全部

热门推荐