• 算法


    <?php

    $model = ["张雪莲1","何香香2","黄雅美3","朱红晓4","梁美丽5"];//模特

    $photographer = ["何濠","张楠","黄金国","陈小厨","潘伟国","张丽珍","钟小敏","王小名","朱辉","艾文平","张大胆","曾小明","汤建","海明珠","胡小注","张里"];//摄影师

    $arr = [2,1,2];//模特分三组 人数为1,2,2

    // 摄影师随机分配
    $nub = count($photographer);//摄影师总人数
    $group = count($arr);//总共分几组
    $y = $nub % $group;//取余数
    $m = round($nub/$group);//每组的人数
    $p = rand(0, ($group-1));//随机数
    //动态拼接数组
    for($i=0;$i<$group;$i++){
    if($p==$i){
    $arr_p[] = $m+$y;
    }else{
    $arr_p[] = $m;
    }
    }

    $a = get_array($model,$arr);//模特
    print_r($a);
    echo "<br/>======================<br/>";
    $b = get_array($photographer,$arr_p);//摄影师
    print_r($b);


    /**
    * 公共算法
    */
    function get_array($arr_nub,$count){
    //模特随机分组
    for($i=0;$i<count($count);$i++){
    /**
    * 备注 array_rand()函数 当被分组的个数为1的时候 ,$arr_new是个整数。
    * 如:array_rand($model,1) 此时的结果是整数数,大于1的时候是个数组。
    */
    //随机取的索引 数组
    $arr_new = array_rand($arr_nub,$count[$i]);
    $leng = "";
    if(is_array($arr_new)){
    $leng = count($arr_new);
    }else{
    $leng = 1;
    }
    $x = "";
    for($j=0;$j<$leng;$j++){
    if($leng == 1){
    $x = $arr_nub[$arr_new];
    unset($arr_nub[$arr_new]);
    }else{
    $str = $arr_nub[$arr_new[$j]];
    $x .= $j==0?$str:",".$str;
    unset($arr_nub[$arr_new[$j]]);
    }
    }
    $temp_arr [$i] = $x;
    }
    return $temp_arr;
    }


    /**
    * 公共算法
    */
    //function get_array($arr_nub,$count){
    // //模特随机分组
    // for($i=0;$i<count($count);$i++){
    // /**
    // * 备注 array_rand()函数 当被分组的个数为1的时候 ,$arr_new是个整数。
    // * 如:array_rand($model,1) 此时的结果是整数数,大于1的时候是个数组。
    // */
    // //随机取的索引 数组
    // $arr_new = array_rand($arr_nub,$count[$i]);
    // $str = "第".($i+1)."组:";
    // $leng = "";
    // if(is_array($arr_new)){
    // $leng = count($arr_new);
    // }else{
    // $leng = 1;
    // }
    // for($j=0;$j<$leng;$j++){
    // if($leng == 1){
    // $str .= $arr_nub[$arr_new].",";
    // unset($arr_nub[$arr_new]);
    // }else{
    // $str .= $arr_nub[$arr_new[$j]].",";
    // unset($arr_nub[$arr_new[$j]]);
    // }
    // }
    // echo $str."<br/>";
    // }
    //}

    //$a=array("red","green","blue","yellow");
    //print_r(array_rand($a,1));


    //$input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
    //$rand_keys = array_rand($input, 3);
    //print $input[$rand_keys[0]] . " ";
    //print $input[$rand_keys[1]] . " ";
    //print $input[$rand_keys[2]] . " ";

  • 相关阅读:
    小酌重构系列[3]——方法、字段的提升和降低
    FPGA实现视频图像的水印添加
    FPGA实现图像中心差分变换
    FPGA实现图像几何变换:缩放
    FPGA实现图像几何变换:平移
    FPGA实现图像几何变换:旋转
    FPGA实现图像几何变换:镜像
    FPGA实现图像几何变换:裁剪
    FPGA实现钢笔画和浮雕效果
    FPGA实现图像的bit平面分层
  • 原文地址:https://www.cnblogs.com/hgj123/p/5252400.html
Copyright © 2020-2023  润新知