比赛

来源:互联网 发布:菜鸟网络的现状 编辑:程序博客网 时间:2024/04/28 10:58
2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛-A banana·

题意很好理解就不说了,实现比较清晰,选择邻接表来做

但是我用的是链表来实现的,所以导致出现了很多问题,最后卡的最长时间的一个问题是

应该从1开始而不是从0开始,读题应该自习一点;

题目如下:

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 TT, indicating that there are TT test cases.

For each test case, the first line contains two integers NN and MM, representing the length of the first and the second lists respectively.

In the each line of following NN lines, two positive integers i, ji,j indicate that the ii-th monkey favours the jj-th type of banana.

In the each line of following MM 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 5050.

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 xxshould 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.

样例输入

16 41 11 22 12 33 34 11 11 32 23 3

样例输出

1 11 21 32 12 33 34 14 3
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;struct node{    int x,y;};bool cmp(node a,node b){    if(a.x==b.x)        return a.y<b.y;    return a.x<b.x;}int main(){
    int t,n,m,num,i,j,x,y,cnt,k;    node c[55],a[55],b[55];    cin>>t;    while(t--)    {
        scanf("%d%d",&n,&m);        //num=0;        cnt=0;        for(i=1;i<=n;i++)        {            scanf("%d%d",&x,&y);            a[i].x=x;            a[i].y=y;            //if(num<x)                //num=x;        }        for(i=1;i<=m;i++)        {
            scanf("%d%d",&x,&y);            b[i].x=x;            b[i].y=y;        }        //for(i=1;i<=num;i++)        //{            for(j=1;j<=n;j++)            {                for(k=1;k<=m;k++)                {                    if(a[j].y==b[k].x)                    {                        c[cnt].x=a[j].x;                        c[cnt].y=b[k].y;                        cnt++;                    }                }           }        //}        sort(c,c+cnt,cmp);        cout<<c[0].x<<" "<<c[0].y<<endl;        for(i=1;i<cnt;i++)        {            if(c[i].x!=c[i-1].x||c[i].y!=c[i-1].y)            cout<<c[i].x<<" "<<c[i].y<<endl;        }        cout<<endl;    }}/*签到题:          猴子 香蕉 香蕉 产地          香蕉是个桥梁输出的是猴子 产地          猴子由小到大输出 猴子一样产地由小到大输出          输出的时候要判断有没有一样的*/