我是靠谱客的博主 含糊香氛,最近开发中收集的这篇文章主要介绍2017 icpc 乌鲁木齐赛区 A.Banana (签到题),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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 the second one records the types of bananas from different places.
Now, the supplier wants to know, whether a monkey can accept at least one type of bananas 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, ji,j indicate that the ii-th monkey favours the j-th type of banana.
In the each line of following M lines, two positive integers j, kj,k indicate that the jj-th type of banana could be find in the kk-th place.
All integers of the input are less than or equal to 50.
Output Format
For each test case, output all the pairs x, yx,y that the xx-the monkey can accept at least one type of bananas from the yy-th place.
These pairs should be outputted as ascending order. That is say that a pair of x, yx,y which owns a smaller xx should be output first.
If two pairs own the same xx, output the one who has a smaller yy first.
And there should be an empty line after each test case.
样例输入

6 4 
1 1 
1 2 
2 1 
2 3 
3 3 
4 1 
1 1 
1 3 
2 2 
3 3 
样例输出
1 1 
1 2 
1 3 
2 1 
2 3 
3 3 
4 1 
4 3


签到题。

#include<iostream>
#include<cstring>
#include<stdio.h>
#include<math.h>
#include<string>
#include<stdio.h>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<deque>
#include<algorithm>
using namespace std;
#define INF 100861111
#define eps 1e-7
#define lson k*2
#define rson k*2+1
#define ll long long
int p1[55][55];
int p2[55][55];
int p3[55][55];
int main()
{
int i,j,k,n,m,x,y,test;
scanf("%d",&test);
while(test--)
{
scanf("%d%d",&n,&m);
memset(p1,0,sizeof(p1));
memset(p2,0,sizeof(p2));
memset(p3,0,sizeof(p3));
for(i=0;i<n;i++)
{
scanf("%d%d",&x,&y);
p1[x][y]=1;
}
for(i=0;i<m;i++)
{
scanf("%d%d",&x,&y);
p2[x][y]=1;
}
for(i=0;i<=50;i++)
{
for(j=0;j<=50;j++)
{
for(k=0;k<=50;k++)
{
if(p1[i][k]&&p2[k][j])
p3[i][j]=1;
}
}
}
for(i=0;i<=50;i++)
{
for(j=0;j<=50;j++)
{
if(p3[i][j])
{
printf("%d %dn",i,j);
}
}
}
printf("n");
}
return 0;
}




最后

以上就是含糊香氛为你收集整理的2017 icpc 乌鲁木齐赛区 A.Banana (签到题)的全部内容,希望文章能够帮你解决2017 icpc 乌鲁木齐赛区 A.Banana (签到题)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(60)

评论列表共有 0 条评论

立即
投稿
返回
顶部