<?php
/**
* 已知条件:$a=75,$b=56,$c=2,$d=25,$e=12,$f=1200,$g=1000
* 根据图知:$k=2$b+$c+$e, $h=2$a+$c+$d
* 求:M个HK切割FG剩余材料最少的算法.
*
* 解:设有x个a, y个b, x和y大于0且为整数
* 那么:HK的面积为:S[hk]=($ax+$c+$d)*($by+$c+$e)
* 即:FG的面积为:S[fg] >= m*S[hk]
* 代入数得:
* 1200000 >= m*(75x+2+25)*(56y+2+12)
*/
class AppMath
{
var $a=75,$b=56,$c=2,$d=25,$e=12,$f=1200,$g=1000;
var $Shk; //HK的面积
var $Sfg; //FG的面积
var $h; //小矩形的高
var $k; //小矩形的宽
var $x; //未知数x个a
var $y; //未知数y个b
var $m; //M个HK切片
var $xy; //代数赋值给xy, 控制循环 (x和y的值不会超过FG的积,即:1200000)
function AppMath(){
$this->m = 4; //当M=1,2,3 时
$this->xy = 1200000; //循环赋值代入法 $this->xy = $this->f * $this->g;
$this->h = 2*$this->a + $this->c + $this->d;
$this->k = 2*$this->b + $this->c + $this->e;
$this->Shk = ($this->a * $this->x + $this->c + $this->d)*($this->b * $this->y + $this->c + $this->e);
$this->Sfg = $this->f * $this->g;
}
function jishuan(){
echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>"
."正在计算中,请耐心等待.......<br>";
for($i=1; $i<$this->m; $i++){ //控制M的变数
for($j=1; $j<$this->xy; $j++){ //控制X的变数
$this->x = $j;
for($k=1; $k<$this->xy; $k++){ //控制Y的变数
$this->y = $k;
//$this->Sfg >= $i * $this->Shk; //不等式
if( $this->Sfg > ($i * $this->Shk) ){ //大于
echo "<br>当S[fg]大于m*S[hk],<font color=red>M={$i}</font> 时:<br>";
echo "<font color=red>X=</font>".$j."<br>";
echo "<font color=red>Y=</font>".$k."<br>";
}
elseif( $this->Sfg == ($i * $this->Shk) ){ //等于
echo "<br>当S[fg]等于m*S[hk],<font color=red>M={$i}</font> 时:<br>";
echo "<font color=red>X=</font>".$j."<br>";
echo "<font color=red>Y=</font>".$k."<br>";
}else{ //小于
echo "<br>无小于情况!<br>";
}
}// end Y
}// end X
}//end M
}
}
/**
* 测试:
* $a = new AppMath;
* $a->jishuan();
*/
?>