D
delphipaladin
Unregistered / Unconfirmed
GUEST, unregistred user!
dingbaosheng 很正确,楼主应该仔细审题。
首先解决第二题:
易错点:
1.(有4个学生) 这4个人是不同的对象
2.(3个不同车间) 这3个也是不同的对象
首先解决第二题:
易错点:
1.(有4个学生) 这4个人是不同的对象
2.(3个不同车间) 这3个也是不同的对象
#include <iostream>
using namespace std;
void main(void)
{
int room;
int place[3][2];
int cnt=0;
int i, j, k, tmp;
bool next;
cout<<"Shop 1/tShop 2/tShop 3"<<endl;
cout<<"----------------------------"<<endl;
for (i=tmp=0, next=false; i<=80; tmp=++i, next=false)
{
for (j=0; j<=2; j++)
for (k=0; k<=2; k++)
place[j][k]=-1;
for (j=0; j<=3; j++)
{
room=tmp%3;
tmp/=3;
if (place[room][0]==-1)
place[room][0]=j;
else if (place[room][1]==-1)
place[room][1]=j;
else
{
next=true;
break;
}
}
if (next) continue;
if (place[0][0]==-1||place[1][0]==-1||place[2][0]==-1)
continue;
for (j=0; j<=2; j++)
if (place[j][0]>place[j][1]&&place[j][1]!=-1)
{
next=true;
break;
}
if (next) continue;
for (j=k=0; j<=2; j++, k=0)
{
while (k<2&&place[j][k]!=-1)
cout<<place[j][k++];
cout<<'/t';
}
cout<<endl;
cnt++;
}
cout<<"----------------------------"<<endl;
cout<<"Total Arrangements: "<<cnt<<endl;
}
Shop 1 Shop 2 Shop 3
----------------------------
23 1 0
23 0 1
13 2 0
3 12 0
03 2 1
3 02 1
3 2 01
13 0 2
03 1 2
3 01 2
3 1 02
3 0 12
12 3 0
2 13 0
02 3 1
2 03 1
2 3 01
1 23 0
0 23 1
01 3 2
1 03 2
1 3 02
0 13 2
0 3 12
12 0 3
02 1 3
2 01 3
2 1 03
2 0 13
01 2 3
1 02 3
1 2 03
0 12 3
0 2 13
1 0 23
0 1 23
----------------------------
Total Arrangements: 36
Option Explicit
Option Base 1
Private Sub Form_Load()
Dim cClass(3) As Collection
Dim i As Long
Dim j As Long
Dim k As Long
Dim tmp As Long
Dim cnt As Long
For i = 0 To 3 ^ 6 - 1
' 初始化 Collection 对象
For j = LBound(cClass) To UBound(cClass)
Set cClass(j) = New VBA.Collection
Next j
' 看看那个到那个班
tmp = i
For j = 1 To 6
k = tmp Mod 3 + 1
tmp = CLng(tmp / 3)
cClass(k).Add j
Next j
' 看看是否符合条件
For j = LBound(cClass) To UBound(cClass)
If cClass(j).Count <> 2 Then GoTo NextLoopLine
If cClass(j).Item(1) > cClass(j).Item(2) Then GoTo NextLoopLine
Next j
' 打印条目
For j = LBound(cClass) To UBound(cClass)
For k = 1 To cClass(j).Count
Text1.Text = Text1.Text + CStr(cClass(j).Item(k))
Next k
Text1.Text = Text1.Text + vbTab
Next j
Text1.Text = Text1.Text + vbCrLf
cnt = cnt + 1
NextLoopLine:
Next i
Text1.Text = Text1.Text + "Totla Arrangement: " + CStr(cnt)
End Sub
56 14 23
56 24 13
56 34 12
26 15 34
16 25 34
36 15 24
36 25 14
16 35 24
26 35 14
46 15 23
46 25 13
46 35 12
16 45 23
26 45 13
36 45 12
23 16 45
13 26 45
12 36 45
24 16 35
14 26 35
34 16 25
34 26 15
14 36 25
24 36 15
12 46 35
13 46 25
23 46 15
25 16 34
15 26 34
35 16 24
35 26 14
15 36 24
25 36 14
45 16 23
45 26 13
45 36 12
15 46 23
25 46 13
35 46 12
12 56 34
13 56 24
23 56 14
14 56 23
24 56 13
34 56 12
34 12 56
24 13 56
14 23 56
23 14 56
13 24 56
12 34 56
35 12 46
25 13 46
15 23 46
45 12 36
45 13 26
45 23 16
25 14 36
15 24 36
35 14 26
35 24 16
15 34 26
25 34 16
23 15 46
13 25 46
12 35 46
24 15 36
14 25 36
34 15 26
34 25 16
14 35 26
24 35 16
12 45 36
13 45 26
23 45 16
36 12 45
26 13 45
16 23 45
46 12 35
46 13 25
46 23 15
26 14 35
16 24 35
36 14 25
36 24 15
16 34 25
26 34 15
56 12 34
56 13 24
56 23 14
Totla Arrangement: 90