fork(1) download
  1. <?php
  2. $test1 = array(10,5);
  3. $test2 = array([0,0.3],[0.2,0]);
  4.  
  5. $l = count($test1);
  6. $c = array();
  7. $c = iniArray($c, 19);
  8. $c = calFactor($test1,$test2, $l);
  9. echo "<br><br> enddd<br>";
  10. echo json_encode($c);
  11.  
  12. function calFactor( $factorList, $relationList, $l)
  13. {
  14. $temp = array();
  15. $temp = iniArray($temp, $l);
  16. $final = array();
  17. $final = iniArray($final, $l);
  18. $flag2 = 0;
  19.  
  20. for($i=0; $i < $l ; $i++)
  21. {
  22. if($factorList[$i]==0)
  23. continue;
  24. else
  25. {
  26. $flag2 = 1;
  27. $partFactorList = array();
  28. $partFactorList = checkArray($factorList[$i],$i ,$l);
  29.  
  30. $temp = countFactor($partFactorList, $relationList, $l, $i);
  31. $checkzero = check($temp, $l);
  32. if($checkzero == 0)
  33. {
  34. $flag2 = 0;
  35. continue;
  36. }
  37.  
  38. else
  39. {
  40. for($j= 0; $j <$l; $j++)
  41. $final[$j] += $temp[$j];
  42. }
  43. }
  44. }
  45. if($flag2==0)
  46. return $factorList;
  47. else
  48. return $final;
  49.  
  50. }
  51. function countFactor($factorList, $relationList, $l, $ptr)
  52. {
  53. $countFactorTemp = array();
  54. $countFactorTemp = iniArray($countFactorTemp, $l);
  55. $countFactorTemp2 = array();
  56. $countFactorTemp2 = iniArray($countFactorTemp2, $l);
  57. $flag = 0;
  58. for($j = 0; $j < $l; $j++)
  59. {
  60. $num = $factorList[$ptr]*$relationList[$ptr][$j];
  61. if( $num < 0.1)
  62. $countFactorTemp[$j]=0;
  63. else
  64. {
  65. $countFactorTemp[$j] = round($num *100)/100;
  66. $flag = 1;
  67. }
  68. }
  69. if($flag ==0)
  70. {
  71. $arr = array();
  72. $arr = iniArray($arr, $l);
  73. return $arr;
  74. }
  75. else
  76. {
  77. $countFactorTemp2 = calFactor($countFactorTemp, $relationList, $l);
  78. for($j= 0; $j <$l; $j++)
  79. {
  80. $countFactorTemp2[$j] += $factorList[$j];
  81. }
  82. return $countFactorTemp2;
  83. }
  84. }
  85. function iniArray($arr,$length)
  86. {
  87. $i;
  88.  
  89. for( $i= 0; $i< $length; $i++)
  90. {
  91. $arr[$i]=0;
  92. }
  93. return $arr;
  94. }
  95. function checkArray($arr,$j ,$l)
  96. {
  97. $temp = array();
  98. for ( $k = 0; $k < $l; $k++)
  99. {
  100. if($k==$j)
  101. $temp[$k] = $arr;
  102. else
  103. $temp[$k]=0;
  104. }
  105. return $temp;
  106. }
  107.  
  108. function check($arr, $l)
  109. {
  110. for($i=0; $i< $l; $i++)
  111. {
  112. if($arr[$i]!=0)
  113. break;
  114. }
  115. if($i != $l)
  116. return 1;
  117. else
  118. return 0;
  119. }
  120. ?>
  121. // your code goes here
Success #stdin #stdout 0s 82880KB
stdin
Standard input is empty
stdout
<br><br> enddd<br>[11.6,8.48]// your code goes here