Algorithm


Problem Name: 2 AD-HOC - beecrowd | 1267

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1267

Pascal Library

 

By Ricardo Anido  Brazil

Timelimit: 1

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. The output must be written to standard output.

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.

 

 

 

Sample Input Sample Output

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

yes
no

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define true 1
#define false 0

int main(int argc, char **argv)
{

	int linhas, colunas, i, j;

	while (scanf("%d %d", &colunas, &linhas), linhas)
	{

		char matrix[linhas][colunas];

		for (i = 0; i  <  linhas; ++i)
			for (j = 0; j  <  colunas; ++j)
				scanf("%hhd", &matrix[i][j]);

		int cont;
		_Bool is = false;
		for (j = 0; j  <  colunas; ++j)
		{

			cont = 0;
			for (i = 0; i  <  linhas; ++i)
				if (matrix[i][j])
					cont++;
			
			if (cont == linhas)
				is = true;

		}

		printf("%s\n", is ? "yes" : "no");

	}

	return 0;

}
Copy The Code & Try With Live Editor

Input

x
+
cmd
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

Output

x
+
cmd
yes
no

#2 Code Example with C++ Programming

Code - C++ Programming


#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i  < = b; ++i)
#define RFOR(i, b, a) for (int i = b; i >= a; --i)
#define REP(i, N) for (int i = 0; i  <  N; ++i)
#define MAX 1000010
#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef long long int64;
typedef unsigned long long uint64;

int bib[510][110], alumn[110];

int main()
{
    int a, b;
    while (scanf("%d %d", &a, &b) && a + b) {
        REP(i, a)
        alumn[i] = 1;
        REP(i, b)
        {
            REP(k, a)
            {
                scanf("%d", &bib[i][k]);
                alumn[k] &= bib[i][k];
            }
        }
        int f = false;
        REP(i, a)
        {
            if (alumn[i] & 1) {
                printf("yes\n");
                f = !f;
                break;
            }
        }
        if (!f)
            printf("no\n");
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
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

Output

x
+
cmd
yes
no

#3 Code Example with Javascript Programming

Code - Javascript Programming


const { readFileSync } = require("fs")
const input = readFileSync("/dev/stdin", "utf8").split("\n").map(line => line.split(" "))

const output = []

while (input.length > 0) {
	const [A, D] = input.shift()

	if (+A == 0 || +D == 0) break
	if (isNaN(+A) || isNaN(+D)) break

	const aluminisList = new Array(+A).fill(true)
	const dinnersList = input.splice(0, +D).map(dinner => dinner.slice(0, +A))

	for (const dinner of dinnersList) {
		for (let index = 0; index  <  dinner.length; index++) {
			if (aluminisList[index] == false) continue
			else if (dinner[index] == "0") aluminisList[index] = false
		}
	}

	output.push(aluminisList.includes(true) ? "yes" : "no")
}

console.log(output.join("\n"))
Copy The Code & Try With Live Editor

Input

x
+
cmd
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

Output

x
+
cmd
yes
no

#4 Code Example with Python Programming

Code - Python Programming


while True:
    e = str(input()).split()
    s = int(e[0])
    t = int(e[1])
    if s == t == 0: break

    m = []
    for i in range(t):
        m.append([int(x) for x in str(input()).split()])

    o = [[lin[j] for lin in m] for j in range(len(m[0]))]

    ok = False
    for i in range(s):
        if o[i].count(0) == 0: ok = True
    print('yes' if ok else 'no')
Copy The Code & Try With Live Editor

Input

x
+
cmd
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

Output

x
+
cmd
yes
no
Advertisements

Demonstration


Previous
#1266 Beecrowd Online Judge Solution 1266 Tornado! Solution in C, C++, Java, Js and Python
Next
#1285 Beecrowd Online Judge Solution 1285 Different Digits Solution in C, C++, Java, Js and Python