离散题目12
2017-05-18 16:33
246 查看
离散题目12
Time Limit: 1000MSMemory Limit: 65536KB
[align=center][/align]
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; }
相关文章推荐