集合相等问题

集合相等问题

Time Limit: 1000MS  Memory Limit: 65536KB
Problem Description
给定2 个集合S和T,试设计一个判定S和T是否相等的蒙特卡罗算法。
设计一个拉斯维加斯算法,对于给定的集合S和T,判定其是否相等。
Input
输入数据的第一行有1 个正整数n(n≤10000),表示集合的大小。接下来的2行,每行有n个正整数,分别表示集合S和T中的元素。
Output
将计算结论输出。集合S和T相等则输出YES,否则输出NO。
Example Input
3
2 3 7
7 2 3
Example Output
YES
import java.util.Random;
import java.util.Scanner;
import java.sql.Time;
import java.time.*;
public class Main{
	static boolean panduan(int a[],int b[],int n){
		if(a.length != b.length)
			return false;
		for(int i = 0; i < a.length; i++){
			 Random r = new Random();
		int j = r.nextInt(a.length);
		int x = a[j];
		for(i = 0; i < b.length; i++){
			if(x == b[i])
				break;
			if(i == b.length-1)
				return false;
		}
		}
		return true;
	}
	public static void main(String args[]){
		Scanner reader = new Scanner(System.in);
		int n;
		n = reader.nextInt();
		int a[] = new int[n];
		int b[] = new int[n];
	
		for(int i = 0; i < n; i++){
		a[i] = reader.nextInt();	
		}
		for(int i = 0; i < n; i++){
			b[i] = reader.nextInt();
		}
		if(panduan(a,b,n))
			System.out.println("YES");
		
		else System.out.println("NO");
		
			
		}
	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值