2018_1_21_Pascal Library_矩阵遍历
2018-01-21 13:10
393 查看
Pascal Library
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
Sample Output
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.
Source
South America 2005
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6384 | Accepted: 2957 |
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.
Source
South America 2005
#include<iostream> #include<string> #include<vector> #include<algorithm> #include<cmath> using namespace std; const int N=500+5; int a ; int main(){ int n,m; while(scanf("%d%d",&n,&m)){ if(n==0&&m==0)return 0; for(int i=0;i<m;i++) for(int j=0;j<n;j++) scanf("%d",&a[i][j]); bool ff=false; for(int i=0;i<n;i++){ bool f=false; for(int j=0;j<m;j++) if(!a[j][i]){f=true;break;} if(!f){ff=true;break;} } if(ff)puts("yes"); else puts("no"); } return 0; }
相关文章推荐
- 2018_1_28_Error Correction_矩阵遍历
- POJ2553 The Bottom of a Graph Tarjan 矩阵 pascal 解题报告
- 把N*N矩阵顺时针旋转90°输出(2018携程校招笔试题)
- Pascal Library
- DFS BFS遍历图 矩阵存储
- 1286. Pascal Library
- 按一定的角度Z字形遍历一个矩阵
- Code the Tree_2018_2_21
- 21.6 windows_21_Library_Variable_DLL&&CPP&&DEF 动态库补充6
- Armadillo C++ linear algebra library 学习笔记(3)——矩阵的基本操作(2)
- leetcode 329. Longest Increasing Path in a Matrix 矩阵中寻找最长递增序列 + 一个典型的深度优先遍历DFS的做法
- JZOJ5242【GDOI2018模拟8.8】矩阵
- 21.Oracle杂记——Oracle常用动态视图v$librarycache
- 【OpenCV学习】错误的案例:矩阵的遍历赋值和取值
- lintcode 容易题:Matrix Zigzag Traversal 矩阵的之字型遍历
- 21.7 windows_21_Library_Variable_DLL_USE 动态库补充7
- Armadillo C++ linear algebra library 学习笔记(4)——矩阵的运算
- POJ 2864 - Pascal Library
- 2018_1_21_Self Numbers_筛法
- CodeForces - Hello 2018 B(树的遍历). C(贪心)