WOJ-feeding animals(Ⅱ)
To show your intelligence to the Lord,you must solve the problem as follows:
Suppose there are m persons and n animals. A person can feed an animal peacefully if he/she is liked by the animal.
Given a list of which person is liked by which animal,you are to determine whether all animals can be feeded peacefully on
condition that every person can feed at most k animals.
输入格式
There will be multiple test cases. For each test case,the first line contains two integers m(1 <= m <= 100) and
n(1 <= n <= 100), where m indicates the number of persons and n indicated the number of animals.The following lines
contain the m * n 0-1 matrix indicating which person is liked by which animal.The ith person is liked by the jth animal
if the jth element of the ith line is 1. The last line for each test case contains a single integer k,indicating the
maximal number of animals one person can feed.
输出格式
For each test case,output "Yes" if all animals can be feeded peacefully,"No" otherwise.
样例输入
2 8
1 1 0 1 0 0 1 1
1 1 1 0 1 1 1 1
2
7 2
1 1
1 1
1 1
1 1
1 1
1 1
1 1
2
样例输出
No
Yes
得到数组a【m】【n】后,应该怎样遍历(或其他方法)数组以确认是否能和平地喂养。
个人理解:n必须是k的整数倍,一个人可以喂多次,但必须是一次喂k个动物,最后所有动物都有人喂。
创建了一个数组b【100】,选出那(n/k)个人(可重复),每人选k个,值置为1,直至全1则可以输出Yes。但是不知怎么实现
向大家请教请教思路方法,有代码更好
#include <stdio.h>
#include <string.h>
int main()
{
int m,n,k,i,j,num,sum=0;
int a[100][100];
int b[100];
while(scanf("%d %d", &m, &n) == 1)
{
for(i=0;i<m;i++) //m men n animals
for(j=0;j<n;j++)
scanf("%d", &a[i][j]);
if(n%k!=0) //
{ printf("No");continue;
}
for(j=0;j<n;j++)
{
for(i=0;i<m;i++)
sum += a[i][j];
if(sum==0) //no one can feed this animal
{ printf("No");continue;
}
... // b[100] !!!!!!!!!!!!!
}
memset(a,0,sizeof(a));
}
}
Suppose there are m persons and n animals. A person can feed an animal peacefully if he/she is liked by the animal.
Given a list of which person is liked by which animal,you are to determine whether all animals can be feeded peacefully on
condition that every person can feed at most k animals.
输入格式
There will be multiple test cases. For each test case,the first line contains two integers m(1 <= m <= 100) and
n(1 <= n <= 100), where m indicates the number of persons and n indicated the number of animals.The following lines
contain the m * n 0-1 matrix indicating which person is liked by which animal.The ith person is liked by the jth animal
if the jth element of the ith line is 1. The last line for each test case contains a single integer k,indicating the
maximal number of animals one person can feed.
输出格式
For each test case,output "Yes" if all animals can be feeded peacefully,"No" otherwise.
样例输入
2 8
1 1 0 1 0 0 1 1
1 1 1 0 1 1 1 1
2
7 2
1 1
1 1
1 1
1 1
1 1
1 1
1 1
2
样例输出
No
Yes
得到数组a【m】【n】后,应该怎样遍历(或其他方法)数组以确认是否能和平地喂养。
个人理解:n必须是k的整数倍,一个人可以喂多次,但必须是一次喂k个动物,最后所有动物都有人喂。
创建了一个数组b【100】,选出那(n/k)个人(可重复),每人选k个,值置为1,直至全1则可以输出Yes。但是不知怎么实现
向大家请教请教思路方法,有代码更好
#include <stdio.h> #include <string.h>
int main()
{
int m,n,k,i,j,num,sum=0;
int a[100][100];
int b[100];
while(scanf("%d %d", &m, &n) == 1)
{
for(i=0;i<m;i++) //m men n animals
for(j=0;j<n;j++)
scanf("%d", &a[i][j]);
if(n%k!=0) //
{ printf("No");continue;
}
for(j=0;j<n;j++)
{
for(i=0;i<m;i++)
sum += a[i][j];
if(sum==0) //no one can feed this animal
{ printf("No");continue;
}
... // b[100] !!!!!!!!!!!!!
}
memset(a,0,sizeof(a));
}
}
...全文
相关推荐
武汉大学 WOJ STARTER 题解 考研复试 机试
在“WOJ_STARTER_byHiJie”这个压缩包文件中,很可能是由一位名为"HiJie"的用户或团队整理的题解集合。
woj-land:woj-land 加强版
woj-land 这是一个分支,其创建者和维护者是 。目标计划对woj-land进行增强。 最近计划: 支持解释型语言(首先是 Python2、Python3 和 Ruby) 支持要求的其他语言(例如
woj1010-Alternate-Sum.rar_SUM
本文将深入探讨这一问题,并结合题目woj1012,详细解析其解决方案。“交替求和”是指对一串数字进行加法运算时,采取交替取数的方式。
woj-test.rar_52_956_925
标题中的"woj-test.rar_52_956_925"可能是指一个包含编程竞赛或算法挑战题目的压缩文件,其中"woj"可能是"编程擂台"(World of Warcraft Jousting)或者"
武大woj文档
从给定的“武大woj文档”中,我们可以提炼出一系列计算机科学,特别是编程竞赛相关的知识点,涉及算法、数据结构、数学等多个方面。


非技术区
