回复 10楼 分号
总分差6分,人数差一个,我只能作到这一步了否则可能要用博弈算法了。
dBase有人接盘了。
Set Safety Off SET TALK OFF Close Tables All Select Distinct bj From 理科 Into Cursor bjmp Order By bj Desc Readwrite ALTER table bjmp ADD px n(12,10) ibjs=Reccount()&&班级数 Dimension arxb(2) SELECT SPACE(8) bj,zkzh,xm, xb,总分,三总,语文,数学,英语,物理,化学,生物,IIF(xb='男',1,0) xb1 FROM 理科 INTO dbf xsmd Replace bj With '' In xsmd All Select zkzh,总分 z1,三总 z2,物理+化学+生物 z3,语文+数学 z4,英语+生物 z5 ,IIF(xb='男',1,0) xb From 理科 Into Cursor xsmdtmp WHERE .t. arxb(1)=1&&'男' arxb(2)=0&&'女' For Each cxb In arxb SELECT bjmp SCAN Replace px With Rand(-99) ENDSCAN IF cxb=0 Select * From bjmp Into Cursor bjxx Order By px Select zkzh From xsmdtmp Into Cursor xsmdxb ORDER BY z1,z2 desc,z3,z4 desc,z5 Where xb=cxb Readwrite ELSE Select * From bjmp Into Cursor bjxx Order By px desc Select zkzh From xsmdtmp Into Cursor xsmdxb ORDER BY z1 desc,z2 ,z3 DESC ,z4,z5 DESC Where xb=cxb Readwrite endif Go Top stbj=1 &&由班级表排位第1的班级(已经随机过了),开始选学生 yprs=0 &&本轮已经排班级数 For i=1 To Reccount('xsmdxb') If yprs=ibjs yprs=1 stbj=Iif(stbj=ibjs,1,stbj+1) Else yprs=yprs+1 Endif ijlbh=yprs+stbj-1-Iif(yprs+stbj-1>ibjs,ibjs,0) Go ijlbh In bjxx Go i In xsmdxb Select xsmd Locate For Alltrim(zkzh)=Alltrim(xsmdxb.zkzh) If Found() Replace bj With bjxx.bj Endif Endfor ENDFOR *以下为统计用,可以不要。 SELECT distinct bj,SUM(xb1) 男生,COUNT(*)-SUM(xb1) 女生,COUNT(*) as 人数,avg(语文) 语文,avg(数学) 数学,avg(英语) 英语,avg(物理) 物理,avg(化学) 化学,avg(生物) 生物 FROM xsmd INTO dbf fbtj GROUP BY bj ALTER table fbtj ADD 总分 n(8,2) ALTER table fbtj ADD 三总 n(8,2) REPLACE 总分 WITH 语文+数学+英语+物理+化学+生物 ,三总 WITH 语文+数学+英语 all CALCULATE avg(总分), avg(三总), avg(语文),avg(数学), avg(英语), avg(物理),avg(化学),avg(生物),AVG(人数),AVG(男生),AVG(女生) TO p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11 APPEND BLANK REPLACE bj WITH '平均',总分 WITH p1, 三总 WITH p2, 语文 WITH p3,数学 WITH p4, 英语 WITH p5, 物理 WITH p6,化学 WITH p7,生物 WITH p8,人数 WITH p9,男生 WITH p10,女生 with p11 CALCULATE max(总分), max(三总), max(语文),max(数学), max(英语), max(物理),max(化学),max(生物),max(人数),MAX(男生),MAX(女生) TO p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11 APPEND BLANK REPLACE bj WITH '最高',总分 WITH p1, 三总 WITH p2, 语文 WITH p3,数学 WITH p4, 英语 WITH p5, 物理 WITH p6,化学 WITH p7,生物 WITH p8,人数 WITH p9,男生 WITH p10,女生 with p11 CALCULATE min(总分), min(三总), min(语文),min(数学), min(英语), min(物理),min(化学),min(生物) ,min(人数),Min(男生),Min(女生) TO p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11 APPEND BLANK REPLACE bj WITH '最低',总分 WITH p1, 三总 WITH p2, 语文 WITH p3,数学 WITH p4, 英语 WITH p5, 物理 WITH p6,化学 WITH p7,生物 WITH p8,人数 WITH p9,男生 WITH p10,女生 with p11
USE 理科 SORT ON xb,总分/d TO 理科分班 USE 理科分班 DIMENSION BHDATA[100,2] BEGINNUMBER=1 &&班号从1开始 ENDNUMBER=40 &&班号到40结束 FOR I=BEGINNUMBER to ENDNUMBER BHDATA[I,1]=I BHDATA[I,2]=0 ENDfor DO WHILE !EOF() = ASORT(BHDATA, 2*BEGINNUMBER,ENDNUMBER-BEGINNUMBER+1) for I=BEGINNUMBER TO ENDNUMBER REPL Bj WITH PADL(BHDATA[I,1],2,[0]) BHDATA[I,2]=BHDATA[I,2]+总分 SKIP 1 IF EOF() EXIT endif ENDfor ENDDO brow