2017年ACM-ICPC乌鲁木齐站网络赛A题--Banana

A: Banana
time limit:200ms            memory limit:131072KB
     Bananas are the favoured food of monkeys.In the forest, there is a Banana Company that provides bananas from different places.The company has two lists.The first list records the types of bananas preferred by different monkeys, and thesecond one records the types of bananas from different places.Now, the supplier wants to know, whether a monkey can accept at least one type ofbananas from a place.Remenber that, there could be more than one types of bananas from a place, and there also could be more than one types of bananas of a monkey's preference.


Input Format
The first line contains an integer T , indicating that there are T test cases.
For each test case, the first line contains two integers N and M, representing the length of the first and the second lists respectively.
In the each line of following N lines, two positive integers i, j indicate that the i-th monkey favours the j-th type of banana.
In the each line of following M lines, two positive integers j, k indicate that the j-th type of banana could be find in the k-th place.

All integers of the input are less than 50.


Output Format
For each test case, output all the pairs x, y that the x-the monkey can accept at least one type of bananas from the y-th place.
These pairs should be outputted as ascending order. That is say that a pair of x, y which owns a smaller x should be output first.
If two pairs own the same x, output the one who has a smaller y first. 
And there should be an empty line after each test case.


Sample Input

1

4

1 1
1 2
2 1
2 3
3 3
4 1
1 1
1 3
2 2

3 3


Sample Output
1 1
1 2
1 3
2 1
2 2
2 3
3 3
4 1

4 3

题目大意:有若干只猴子喜欢若干种香蕉,每一种类的香蕉可以来自若干产地,问每只猴子能吃到自己喜欢香蕉种类有哪些,并打印出来,见样例解释,具体AC代码如下:

#include<stdio.h>
#include<string.h>
int a[2501][2];
int b[2501][2];
int c[51][5051];
int n,m;
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		memset(c,0,sizeof(c));//刚开始所以种类赋初值都不能吃到
		scanf("%d%d",&n,&m);
		for(int i=0;i<n;i++) scanf("%d%d",&a[i][0],&a[i][1]);
		for(int i=0;i<m;i++) scanf("%d%d",&b[i][0],&b[i][1]);
		for(int i=0;i<n;i++)
		{
			int k=a[i][0];
			for(int j=0;j<m;j++)
			{
				if(b[j][0]==a[i][1]) c[k][b[j][1]]=1;//能够吃到的香蕉的方式置为1
			}
		}
		//扫描每一行,行下标代表猴子个数,编号为i,列下标表示香蕉种类
		for(int i=1;i<=50;i++)
		{
			for(int j=1;j<=5050;j++)
			{
				if(c[i][j]==1) printf("%d %d\n",i,j);
			}
		}
		printf("\n");
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值