Hdoj 1083 Courses

Source: Internet
Author: User

Courses

Time limit:20000/10000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 4669 Accepted Submission (s): 2230


Problem Descriptionconsider A group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine whether it was possible to form a committee of exactly P students that satisfies simultaneously t He conditions:

. Every student in the Committee represents a different course (a student can represent a course if he/she visits that cours E

. Each course have a representative in the Committee

Your program should read sets of the data from a text file. The first line of the input file contains the number of the data sets. Each data set was presented in the following format:

P N
Count1 Student1 1 Student1 2 ... Student1 Count1
Count2 Student2 1 Student2 2 ... Student2 Count2
......
COUNTP STUDENTP 1 studentp 2 ... STUDENTP COUNTP

The first line, each data set contains, positive integers separated by one blank:p (1 <= P <=)-The Numbe R of courses and N (1 <= n <=)-the number of students. The next P lines describe in sequence of the courses. From course 1 to course P, each line describing a course. The description of course I was a line this starts with an integer Count I (0 <= Count i <= N) representing the Numbe R of Students visiting course I. Next, after a blank, you'll find the Count I students, visiting the course, each of the consecutive separated by one blank. Students is numbered with the positive integers from 1 to N.

There is no blank lines between consecutive sets of data. Input data is correct.

The result of the program is in the standard output. For each input data set, prints on a, "YES" if it is possible to form a committee and "NO" otherwise . There should not being any leading blanks at the start of the line.

An example of program input and output:

Sample Input23 33 1 2 32 1 21 13 32 1 32 1 31 1

Sample Outputyesno See English problems on the headache, do not understand ah sad ... The problem is that if you want to have a candidate for each course, and the person who chooses the course can not choose another class output yes otherwise output no with the Hungarian algorithm if the last pair of total logarithm equals the total number of lessons is correct
#include <stdio.h> #include <string.h> #define MAX 1100int cour,stu,p;int map[max][max];int Vis[max],s[max] ; int find (int x) {int i,j;for (i=1;i<=stu;i++) {if (map[x][i]&&vis[i]==0)//If the student is interested in this course and is not marked {          // (This is marked to mean that the first student has chosen this course) Vis[i]=1;if (s[i]==0| | Find (S[i])//If the first student does not choose a class or can change course {s[i]=x;//The first student to take this course return 1;}} return 0;} int main () {int i,j,k,t,sum;scanf ("%d", &t), while (t--) {scanf ("%d%d", &cour,&stu); Memset (Map,0,sizeof ( MAP), memset (s,0,sizeof (s)), for (i=1;i<=cour;i++) {scanf ("%d", &p), and while (p--) {scanf ("%d", &k); Map[i][k] =1;//to the corresponding course and corresponding student Mark}}sum=0;for (i=1;i<=cour;i++) {memset (vis,0,sizeof (VIS)); if (find (i)) sum++;} if (sum==cour) printf ("yes\n"); elseprintf ("no\n");} return 0;}

  

Hdoj 1083 Courses

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.