当前位置: 首页 > news >正文

研究网站平台建设工作动态华仁建设网站

研究网站平台建设工作动态,华仁建设网站,做图片视频的网站有哪些问题吗,网站建设投资规划文章目录 场景TreeMap.tailMap方法简单分析使用随机值使用treemap实现权重取值将Int改为Double稍微准确一点,因为double随机的值更加多测试main方法 当权重的参数比较多,那么建议使用hutool封装的 场景 按照权重2,8给用户分组为A,B, TreeMap.tailMap方法 treeMap是一种基于红… 文章目录 场景TreeMap.tailMap方法简单分析使用随机值使用treemap实现权重取值将Int改为Double稍微准确一点,因为double随机的值更加多测试main方法 当权重的参数比较多,那么建议使用hutool封装的 场景 按照权重2,8给用户分组为A,B, TreeMap.tailMap方法 treeMap是一种基于红黑树实现的有序映射表提供了一系列的方法来操作映射表中的元素。其中tailMap方法是用于返回映射表中大于或等于给定键的部分视图。 tailMap方法的定义如下 public NavigableMapK,V tailMap(K fromKey, boolean inclusive) {return new AscendingSubMap(this,false, fromKey, inclusive,true, null, true);}其中fromKey表示起始键返回一个从fromKey开始到映射表末尾的部分视图。inclusive是表示是否包含传入的fronKey.这个部分视图是SortedMap类型的可以进行排序操作。 使用tailMap方法需要注意以下几点 如果fromKey不存在于映射表中则返回的部分视图将包含大于fromKey的所有键值对。返回的部分视图是映射表的一个视图对这个视图所做的修改会影响到原映射表。返回的部分视图是有序的可以进行排序操作。 下面是一个示例代码 import java.util.TreeMap; import java.util.SortedMap;public class TreeMapExample {public static void main(String[] args) {TreeMapInteger, String treeMap new TreeMap();treeMap.put(1, one);treeMap.put(2, two);treeMap.put(3, three);treeMap.put(4, four);treeMap.put(5, five);// 返回大于等于3的部分视图SortedMapInteger, String tailMap treeMap.tailMap(3);System.out.println(tailMap); // 输出 {3three, 4four, 5five}// 修改部分视图tailMap.put(6, six);System.out.println(treeMap); // 输出 {1one, 2two, 3three, 4four, 5five, 6six}// 对部分视图进行排序SortedMapInteger, String sortedTailMap tailMap.descendingMap();System.out.println(sortedTailMap); // 输出 {6six, 5five, 4four, 3three}} }在上面的示例代码中首先创建了一个treeMap对象并向其中添加了5个键值对。然后使用tailMap方法返回了大于等于3的部分视图并对这个部分视图进行了修改和排序操作。 tailMap方法是Java中treeMap类提供的一个非常有用的方法可以方便地获取映射表中大于等于指定键的部分视图并进行排序和修改操作。 针对这个特性可以用来获取权重值 简单分析 好比A:B的权重为2:8,那么相当于A的权重为0-2,B的权重为2-10(28)都是包左不包右的; 那我们就可以随机个0-10的值,如果在0-2那么返回A,如果2-10那就返回B 使用随机值 public static String test1() {Random random new Random();int i random.nextInt(10);if (i 2) {return A;} else if (i 2 i 10) {return B;} else {return C;}}使用treemap实现权重取值 public static String test2() {TreeMapInteger, String treeMap new TreeMap();int total 2 8;treeMap.put(2, A);treeMap.put(total, B);Random random new Random();return treeMap.tailMap(random.nextInt(total), false).firstEntry().getValue();}将Int改为Double稍微准确一点,因为double随机的值更加多 public static String test3() {TreeMapDouble, String treeMap new TreeMap();int total 2 8;treeMap.put((double) 2, A);treeMap.put((double) total, B);Random random new Random();return treeMap.tailMap(total * random.nextDouble(), false).firstEntry().getValue();} 测试main方法 package com.study.springbootplus.test;import cn.hutool.core.lang.WeightRandom; import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.RandomUtil;import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.TreeMap;/*** ClassName RandomTest* Author yida* Date 2023-09-14 18:26* Description RandomTest*/ public class RandomTest {public static void main(String[] args) {int num_a 0, num_b 0, num_c 0;int testCount 1000;for (int i 0; i testCount; i) {switch (test3()) {case A:num_a num_a 1;break;case B:num_b num_b 1;break;case C:num_c num_c 1;break;}}System.out.println(A- num_a ------- NumberUtil.div(num_a, testCount, 2) * 100 %);System.out.println(B- num_b ------- NumberUtil.div(num_b, testCount, 2) * 100 %);System.out.println(C- num_c ------- NumberUtil.div(num_c, testCount, 2) * 100 %);}public static String test1() {Random random new Random();int i random.nextInt(10);if (i 2) {return A;} else if (i 2 i 10) {return B;} else {return C;}}public static String test2() {TreeMapInteger, String treeMap new TreeMap();int total 2 8;treeMap.put(2, A);treeMap.put(total, B);Random random new Random();return treeMap.tailMap(random.nextInt(total), false).firstEntry().getValue();}public static String test3() {TreeMapDouble, String treeMap new TreeMap();int total 2 8;treeMap.put((double) 2, A);treeMap.put((double) total, B);Random random new Random();return treeMap.tailMap(total * random.nextDouble(), false).firstEntry().getValue();}public static void test() {ListWeightRandom.WeightObjString weightList new ArrayList();weightList.add(new WeightRandom.WeightObj(A, 20));weightList.add(new WeightRandom.WeightObj(B, 30));weightList.add(new WeightRandom.WeightObj(C, 40));weightList.add(new WeightRandom.WeightObj(D, 10));WeightRandomString wr RandomUtil.weightRandom(weightList);String str ;int num_a 0, num_b 0, num_c 0, num_d 0;int testCount 10000;for (int i 0; i testCount; i) {str wr.next();switch (str) {case A:num_a num_a 1;break;case B:num_b num_b 1;break;case C:num_c num_c 1;break;case D:num_d num_d 1;break;}}System.out.println(A- num_a ------- NumberUtil.div(num_a, testCount, 2) * 100 %);System.out.println(B- num_b ------- NumberUtil.div(num_b, testCount, 2) * 100 %);System.out.println(C- num_c ------- NumberUtil.div(num_c, testCount, 2) * 100 %);System.out.println(D- num_d ------- NumberUtil.div(num_d, testCount, 2) * 100 %);}} 测试结果: A-195-------20.0% B-805-------81.0% C-0-------0.0% 如果测试基数越大,则越准确 当权重的参数比较多,那么建议使用hutool封装的 使用hutool返回权重值 原创
http://www.dnsts.com.cn/news/66536.html

相关文章:

  • php网站留言石家庄的网站开发公司
  • 做一下网站需要什么条件wordpress 默认模版
  • 网站建设怎么宣传免费申请商城网站
  • 购买网站域名空间网站转微信小程序
  • 如何把电脑改成服务器 做网站哈尔滨网络公司招聘信息
  • 用脚手架如何搭建项目做网站哈尔滨网站优化
  • 网站默认后台深圳网络科技有限公司简介
  • 抚顺地区网站建设长沙微信网站开发
  • h5制作网站哪个好资源链接搜索引擎
  • 网站如何做mipwordpress 更改插件样式
  • 贵州省住房和建设厅网网站详情页模板套用
  • 江苏赛华建设监理有限公司网站网页进不去是怎么回事
  • 做电商有哪些网站有哪些新手建站广告联盟赚钱
  • 济南wordpress 建站wordpress搭建工单
  • 手机网站制作建设单网页网站
  • 宜兴市网站建设河南建设工程信息网招标公告
  • 网站开发薪水一般多少钱黄山冬季旅游攻略
  • 做网站是不是需要服务器wordpress苗木模板
  • 嘉兴网站搭建wordpress冷门二次元主题
  • 钦州浦北网站建设wordpress备案号添加到哪里
  • 别人做的网站自己根目录吗企业宽带解决方案
  • 车子网站短链接生成站长工具
  • 秦皇岛新闻最新消息广东网站建设seo优化
  • 内蒙古生态文明建设相关网站网站的备案流程图
  • 石家庄网站app制作网站建设需要几步
  • 建立主题网站的顺序一般是软件开发申请专利流程
  • 专业网站建设制作一家公司可以做几个网站
  • 网站建设品牌营销方正隶变简体可以做网站用么
  • 什么行业要做网站建设推广这些网站怎么做百科
  • 手机上怎么做微电影网站郑州做企业网站哪家好