hdu1144 Prerequisites java版

Description
有k门课可以选,现在要选课n次,每次从c门课中选取r门可选课,问选课是否达标
Input
多组输入,每组用例第一行为两个整数k和m分别表示可选课数量和选课次数,第二行为k个四位整数表示可选课名称,之后m行为选课情况,每行前两个整数c和r表示此次选课数量和需选数量,之后c个四位整数表示此次选课选了哪些课,以k=0结束输入
Output
对于每组用例,如果选课达标则输出yes,否则输出no
Sample Input
3 2
0123 9876 2222
2 1 8888 2222
3 2 9876 2222 7654
3 2
0123 9876 2222
2 2 8888 2222
3 2 7654 9876 2222
0
Sample Output
yes
no

AC代码



import java.util.Scanner;

public class Main{

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner scan=new Scanner(System.in);
        int a[]=new int[102];
        int k,m,c,r,res=0;
        boolean flag;
        while(((k=scan.nextInt())!=0)){
            flag=true;

            m=scan.nextInt();
            for(int i=0;i<k;i++){
                a[i]=scan.nextInt();
            }
            for(int i=0;i<m;i++){
                c=scan.nextInt();
                r=scan.nextInt();
                res=0;
                for(int j=0;j<c;j++){
                    int d=scan.nextInt();
                    for(int x=0;x<k;x++){
                        if(d==a[x]){
                            res++;
                        }
                    }
                }
                if(res>=r){
                    continue;
                }else{
                    flag=false;
                }
            }
            if(flag){
                System.out.println("yes");
            }else{
                System.out.println("no");
            }
        }
    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值