hdu 1144 Prerequisites

3273 ワード

タイトルの住所:
http://acm.hdu.edu.cn/showproblem.php?pid=1144
テーマの説明:
Prerequisites
Time Limit:2000/1000 MS(Java/Others)    メモリLimit:65536/32768 K(Java/Others)Total Submission(s):900    Acceepted Submission(s):561
Problem Description
Freedie the frosh has chocsen to Take courses.To meet the degree requirements,he must courses from each of several categories.Can you asure Freedie Freethat he will gradate,based on course selection? 
 
Input
Input consists of several test cases.For each case,the first line of input contains 1≦k≦100,the number of courses Freedie has chsen,and 0≦m≦100,the number of categories.One more lines.One line line follection 4-ingent。each is the number of a course selected by Freedie.Each category is represented by a line containing 1≦c≦100,the number of courses in the category,0≦r≦c,the minum number of courses from the catember catemberand the c course number s in the category.Each course number is a 4-digit integer.The same course may fulfil several category requiremens.Freedie's selections,and the course numbers iness in partore.catres.categoring.cantry.ore.catetre.cants.cation。
 
Output
For each test case、output a line containing“yes”freedie's course selection meets the degree requements;otherswise output「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
件名:
授業を選んで、k科目を選んで、各科目は課程番号を与えて、m種類の課程があって、各種類の課程はcつの課程があって、この種類の課程で少なくともr門の課程を選んでやっと単位を達成することができます。
クイズ:
各クラスはrコースの数を満足すればいいです。つまり、各サンプルの第3~m行は各コースのrコースの選択を満足して通過できます。一行が通過しない限り、通過できません。このrコースはコース番号によって合わせられます。3~m行で選択したこれらのコース番号は2行目のコースに関連していますか?説明があれば一つ満足します。だから、コードを参照してください。
コード:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
using namespace std;
int course[100]={0};
int k=0,m=0,c=0,r=0;
int cates[100]={0};
int main()
{
    while(scanf("%d",&k)!=EOF&&k>0)
    {
        int flag=1;//initialize the case is available
        scanf("%d",&m);
        for(int i=0;i<=k-1;i++)
        {
            scanf("%04d",&course[i]);
        }
        for(int i=0;i<=m-1;i++)
        {
            scanf("%d%d",&c,&r);
            int passcnt=0;
            for(int j=0;j<=c-1;j++)
            {
                int degree=0;
                scanf("%d",°ree);
                for(int x=0;x<=k-1;x++)
                {
                    if(course[x]==degree)
                    {
                        passcnt++;
                    }
                }
            }
            if(passcnt<r)
            {
                flag=0;
            }
        }
        if(!flag)
        {
            printf("no
"); } else { printf("yes
"); } } return(0); }