sdut-离散题目9
来源:互联网 发布:淘宝网儿童保护电插头 编辑:程序博客网 时间:2024/05/17 06:28
离散题目9
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
Problem Description
给定一个数学函数F和两个集合A,B,写一个程序来确定函数是单射。
即A中的任意一个元素唯一的对应一个函数值,并且该值为B集合中的某个元素。
Input
多组输入。
首先输入集合的元素数n<=100000。
接下来的一行输入n 个整数0<=ai<=n。
接下来的一行输入n个整数 0<=bi<=n。
接下来的一行输入2n个整数ci,并且当ci的下标为奇数时表示A集合中的元素,当ci的下标为偶数时表示A集合中元素对应的函数值(即B集合的元素)。
Output
(一组答案占一行)
当满足单射关系时输出yes
不满足关系时输出no
Example Input
4
1 3 5 7
2 5 6 8
1 2 3 2 5 8 7 6
2
1 4
3 5
1 3 1 5
Example Output
yes
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
Problem Description
给定一个数学函数F和两个集合A,B,写一个程序来确定函数是单射。
即A中的任意一个元素唯一的对应一个函数值,并且该值为B集合中的某个元素。
Input
多组输入。
首先输入集合的元素数n<=100000。
接下来的一行输入n 个整数0<=ai<=n。
接下来的一行输入n个整数 0<=bi<=n。
接下来的一行输入2n个整数ci,并且当ci的下标为奇数时表示A集合中的元素,当ci的下标为偶数时表示A集合中元素对应的函数值(即B集合的元素)。
Output
(一组答案占一行)
当满足单射关系时输出yes
不满足关系时输出no
Example Input
4
1 3 5 7
2 5 6 8
1 2 3 2 5 8 7 6
2
1 4
3 5
1 3 1 5
Example Output
yes
no
坑点: 确保 所有的函数对应关系的 数值 都在两个函数里面,同时也需要保证不能有一个x 对应两个y
#include <stdio.h>#include <string.h>#include<algorithm>using namespace std;int a[150000];int b[150000];int A[150000];int B[150000];int main (){ int n,i,j; while (~scanf("%d",&n) ) { memset(A,0,sizeof(A)); memset(B,0,sizeof(B)); for(i=0; i<n; i++) { scanf("%d",&a[i]); A[a[i] ]=1; } for(i=0; i<n; i++) { scanf("%d",&b[i]); B[b[i] ]=1; } int x; int f=1; for(i=0; i<2*n; i++) { scanf("%d",&x); if(i%2==0) { if(A[x]==1) { A[x]=0; } else f=0; } else { if(B[x]!=1) f=0; } } if( f==1) printf("yes\n"); else printf("no\n"); }}
阅读全文
0 0
- sdut-离散题目9
- SDUT 3803 离散题目9
- sdut离散题目11
- sdut离散题目13
- sdut离散题目14
- SDUT-离散题目13
- SDUT-离散题目7
- SDUT离散题目4
- sdut-离散题目3
- sdut- 离散题目4
- sdut-离散题目5
- sdut-离散题目6
- sdut-离散题目7
- sdut-离散题目8
- sdut-离散题目10
- sdut-离散题目11
- sdut-离散题目12
- sdut-离散题目13
- 5月26日,每日20行。
- 循环神经网络(RNN, Recurrent Neural Networks)介绍
- zoj1203
- 1.1 Getting the Source Tree
- Java中的static详解
- sdut-离散题目9
- 分布式系统概述(来自学习资料)
- MacOS下MySQL 乱码问题解决方法
- 1.1 获取源代码树
- 读书笔记《Effective C++》条款36:绝不重新定义继承而来的non-virtual函数
- 网站异常发送异常代码到邮箱
- ios 代理、block和通知
- C#167课的主要内容
- c语言排序