11选5数据



import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

public class MainControl {
private static final int NEED_ELE = 5;
private static final int MAX_NUM = 11;

public static void main(String[] args) {
getElement();
for (int v = 15; v <= 45; v++) {
System.out.print(v + ":");
Set<Entry<List<Integer>, Integer>> entrySet = dataMap.entrySet();
int count = 0;
List<List<Integer>> data = new ArrayList<List<Integer>>();
for (Entry<List<Integer>, Integer> entry : entrySet) {
Integer value = entry.getValue();
if (value == v) {
count++;
data.add(entry.getKey());
}
}
System.out.print("共" + count + "注,");
System.out.print(" 附注:");
for (List<Integer> dataLs : data) {
System.out.print(dataLs);
}
System.out.println(" 完!");
}
}

private static void getElement() {
int totalSize = combination(5);
int index = 1;
while(index <= totalSize) {
if (getPerEle()) {
index++;
}
}
}

private static Map<List<Integer>, Integer> dataMap = new HashMap<List<Integer>, Integer>();
private static boolean getPerEle() {
List<Integer> dataLs = new ArrayList<Integer>();
for (int i = 1; dataLs.size() < NEED_ELE; i++) {
int ran = random(MAX_NUM);
if (!dataLs.contains(ran)) {
dataLs.add(ran);
}
}
Collections.sort(dataLs);
if (dataMap.isEmpty() || notContain(dataLs)) {
dataMap.put(dataLs, sum(dataLs));
return true;
}
return false;
}

private static boolean notContain(List<Integer> dataLs) {
for (List<Integer> dataTmp : dataMap.keySet()) {
if (dataTmp.toString().equals(dataLs.toString())) {
return false;
}
}
return true;
}

private static int sum(List<Integer> dataLs) {
int sum = 0;
for (Integer perData : dataLs) {
sum += perData;
}
return sum;
}

private static int random(int n) {
return (int)Math.floor((Math.random() * n)) + 1;
}

private static int combination(int m) {
return factorial(MAX_NUM)/factorial(m)/factorial(MAX_NUM-m);
}

private static int factorial(int n) {
if (n == 1)
return 1;
return n * factorial(n-1);
}

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值