WOJ-feeding animals(Ⅱ)

jin75775 2017-10-25 01:50:26
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));
}

}
...全文
398 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jin75775 2017-10-25
  • 打赏
  • 举报
回复
。。行吧,我看看网络流,谢谢了
FancyMouse 2017-10-25
  • 打赏
  • 举报
回复
你理解错了。 赤裸裸的网络流,没学到那就不要浪费时间自己空想了,要么换题要么去学网络流。

15,440

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧