Pascal Library

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 4239 Accepted: 2037

Description

Pascal University, one of the oldest in the country, needs to renovate its Library Building, because after all these centuries the building started to show the effects of supporting the weight of the enormous amount of books it houses.

To help in the renovation, the Alumni Association of the University decided to organize a series of fund-raising dinners, for which all alumni were invited. These events proved to be a huge success and several were organized during the past year. (One of the reasons for the success of this initiative seems to be the fact that students that went through the Pascal system of education have fond memories of that time and would love to see a renovated Pascal Library.)

The organizers maintained a spreadsheet indicating which alumni participated in each dinner. Now they want your help to determine whether any alumnus or alumna took part in all of the dinners.

Input

The input contains several test cases. The first line of a test case contains two integers N and D indicating respectively the number of alumni and the number of dinners organized (1 <= N <= 100 and 1 <= D <= 500). Alumni are identified by integers from 1 to N. Each of the next D lines describes the attendees of a dinner, and contains N integers Xi indicating if the alumnus/alumna i attended that dinner (Xi = 1) or not (Xi = 0). The end of input is indicated by N = D = 0.

Output

For each test case in the input your program must produce one line of output, containing either the word `yes’, in case there exists at least one alumnus/alumna that attended all dinners, or the word `no’ otherwise.

Sample Input

3 3
1 1 1
0 1 1
1 1 1
7 2
1 0 1 0 1 0 1
0 1 0 1 0 1 0
0 0

Sample Output

yes
no

Hint

Alumna: a former female student of a particular school, college or university.
Alumnus: a former male student of a particular school, college or university.
Alumni: former students of either sex of a particular school, college or university.
解:
这道题是计算是否至少有一个校友出席每次的宴会,先初始化所有的校友,标识为1,然后如果有一次没出席就把标识改为0,最后判断是否存在标识为1的,这样就可以说明存在至少有一个校友出席了每次的宴会。
#include <stdio.h>
int main()
{
	int x, y;
	while(scanf("%d %d", &x, &y)) {
		if (x == 0 && y == 0) {
			return 0;
		}
		int n;
		int record[100];
		for (int i = 0; i < x; i++) {
			record[i] = 1;
		}
		for (int i = 0; i < y; i++) {
			for (int j = 0; j < x; j++) {
				scanf("%d", &n);
				if (n == 0) {
					record[j] = 0;
				}
			}
		}
		bool yesornot = false;
		for (int i = 0; i < x; i++) {
			if (record[i] == 1) {
				yesornot = true;
				break;
			}
		}
		yesornot ? printf("yes\n") : printf("no\n");
	}
	return 0;
}
Result Memory Time Language Code Length
Accepted 164K 16MS C++ 563B

 

Tonitech版权所有 | 转载请注明出处: http://www.tonitech.com/1746.html

发表评论