这种题真的是为难批处理了~~~
搞了半天,还是不能通用!!只能就题解答
- @echo off&setlocal enabledelayedexpansion
-
- ::////////////////////////
- for /f "tokens=1-2 delims=米*支" %%a in (%~nx0) do (
- if "%%a" equ "铝材:" set s=lc&set n=
- if "%%a" equ "切割:" set s=cg&set/a lcx=!n!-1&set n=
- if defined s if defined n set !s!!n!=%%a&set !s!!n!n=%%b&set vars=!vars! !s!!n!
- set /a n+=1
- )
- set/a cgx=!n!-1
- :::://////把数据读入到变量
-
- ::set lc
- ::set cg
- ::set vars
- ::pause
-
- ::////////////////////////
- for %%a in (%vars%) do (
- for /f "delims=. tokens=1,2" %%c in ("!%%a!") do (set ver=%%d0)
- set d=0
- for /l %%b in (0,1,10) do (
- if "!ver:~%%b,1!" neq "" set d=%%b
- )
- set d%%a=!d!
- if !d! gtr !dot! set dot=!d!
- )
- set ver=0000000000
-
- for %%a in (%vars%) do (
- set /a n=dot-d%%a
- for %%b in (!n!) do set d%%a=!%%a:.=!!ver:~,%%b!
- )
- ::set d
- ::pause
- ::////////////小数位调整
-
-
-
- ::////////////////////////
- for /l %%a in (1,1,!cgx!) do (
- for /l %%b in (1,1,!cgx!) do (
- if !cg%%a! leq !cg%%b! set /a bcg%%a+=1
- ))
-
- set n=0
- for /l %%a in (1,1,!cgx!) do (
- for %%b in (mum!bcg%%a!) do (
- set /a n+=1
- set %%b=!%%b! cg%%a
- ))
-
- for /l %%a in (1,1,!n!) do set vv=!vv! !mum%%a!&set bcg%%a=&set num%%a=
- ::echo; !vv!
- ::pause
- ::///////要切割规格排序
-
-
- for %%a in (%vv%) do (
- set vvn=!vv:*%%a=!
- set gnn=!d%%a!
- for /l %%b in (1,1,!lcx!) do (
- set /a nn=dlc%%b %% d%%a
- if !nn! lss !gnn! set gnn=!nn!&set gxx=lc%%b
- for %%c in (!vvn!) do (
- set /a mm=nn %% d%%c
- if !mm! lss !gnn! set gnn=!mm!&set gxx=lc%%b %%c
-
- ))
-
- rem 首先切规格最长的,并且配合其它规格,选最省切法
-
- for /f "tokens=1,2" %%b in ("!gxx!") do (
- set/a ##v=d%%b/d%%a,##y=d%%b %% d%%a,##y=##y/d%%c
-
- set/a ##s1=%%an/##v,##s2=##s1,##xy=%%an %% ##v
-
- set gvv=!d%%a!
- if !##xy! neq 0 (
- set/a ##k=%%an-##s1*##v
- set/a ##s1+=1,##k=d%%b-##k*d%%a
- for %%d in (!vvn! lc1) do (
- set /a mm=##k %% d%%d
- if !mm! leq !gvv! set gvv=!mm!&set gxx=%%d
- )
- )
-
- set/a ##x1=%%an,##x2=##s2*##y,%%an=0
- set/a #d%%b=##s1+#d%%b,%%cn=%%cn-##x2,#lf1=gnn*##s2
-
- echo;使用!%%b!米铝材 !##s1!根
- set /p =切成:!%%a!米长!##x1!根,还差0根<NUL
- if !##y! neq 0 (echo;,!%%c!米长!##x2!根,还差!%%cn!根<NUL) echo;
-
- if !gvv! neq !d%%a! (
- for %%d in (!gxx!) do (
- echo;二次利用:!##k:~,-%d%!.!##k:~-%d%!米 切得:
- set/a ##k1=##k/d%%d, ##k2=##k %% d%%d,%%dn=%%dn-##k1
- echo; !%%d!米长!##k1!根 还差:!%%dn!根,仍剩:0!##k2:~,-%d%!.!##k2:~-%d%!米
- set/a #lf1=#lf1+##k2
- ))
- echo;本次浪费:0!#lf1:~,-%d%!.!#lf1:~-%d%!米
- echo;
-
- set/a #lf=#lf+#lf1
- )
- )
-
- for /l %%a in (1,1,!lcx!) do (
- echo;共用材料:!lc%%a!米,!#dlc%%a!根
- )
- echo;共浪费材料:!#lf:~,-%d%!.!#lf:~-%d%!米
-
- pause
-
- exit/b
-
- ::数据定义
- 铝材:
-
- 6米
- 5.4米
-
- 切割:
-
- 1.8米*10支
- 1.5米*20支
- 2.2米*30支
- 3.1米*15支
复制代码
[ 本帖最后由 netbenton 于 2010-5-26 23:01 编辑 ] |