离散题目12
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
Problem Description
给出两个集合,以及两个集合上的关系。判断该关系能不能构成函数
Input
多组输入。第一行数字表示集合A;第二行数字表示集合B;第三行一个数字N,表示关系的个数。以下N行,每行两个数字a b,用来描述关系a→b。0 < n < = 20000,集合A、B的大小不超过10000.
Output
每组数据输出一行,所给关系属于函数,输出’yes’ ,否则输出‘no’。
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
Think:判断集合A中的元素是否都出现且出现一次
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
char a[111111];
char b[111111];
while(gets(a))
{
gets(b);
int n;
int aa[111111];
int bb[111111];
scanf("%d",&n);
int i;
for(i=0; i<n; i++)
{
scanf("%d %d",&aa[i],&bb[i]);
}
sort(aa,aa+n);
int k=0;
for(i=0; i<n-1; i++)
{
if(aa[i]==aa[i+1])
{
k=1;
break;
}
}
if(k==0) printf("yes\n");
else printf("no\n");
getchar();
getchar();
}
return 0;
}
1155




被折叠的 条评论
为什么被折叠?



