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");
}
}
}
}