离散题目12

离散题目12

Time Limit: 1000MS Memory Limit: 65536KB
Problem Description

给出两个集合,以及两个集合上的关系。判断该关系能不能构成函数 

Input

多组输入。第一行数字表示集合A;第二行数字表示集合B;第三行一个数字N,表示关系的个数。以下N行,每行两个数字a b,用来描述关系a→b。0 < n < = 20000,集合A、B的大小不超过10000.

Output

每组数据输出一行,所给关系属于函数

Example Input
1 2 3
4 5 6
3
1 4
2 5
3 6
1 2 3
4 5 6
3
1 4
1 5
1 6
Example Output
yes
no
我开始怀疑离散课本上的定义了。。
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,n;
    set<int> a,b;
    map<int,int>m;
    vector<int>::iterator it;
    map<string,int>::iterator iter;
    string sa,sb;
    string aaaa;
    while(getline(cin,sa))
    {
        getline(cin,sb);
        cin>>n;
        stringstream ss(sa);
        int t;
        while(ss>>t)
        {
            a.insert(t);
        }
        stringstream cc(sb);
        while(cc>>t)
        {
            b.insert(t);
        }
        int flag=1;
        while(n--)
        {
            int x,y;
            cin>>x>>y;
            if(a.count(x)&&b.count(y))
            {
                if(m.count(x)!=0)//x是否重复出现
                    flag=0;
                else m[x]=y;
            }
            else
            {
                flag=0;
            }
        }
        if(flag) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
        getline(cin,aaaa);
        a.clear();
        b.clear();
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值