Re: 请高手帮小弟一个忙

楼主: Yaiba (绯心刀刃)   2016-11-05 02:00:33
Option Explicit
Private Sub CmdRun_Click()
Dim iIndexX As Integer
Dim iIndexY As Integer
Dim iIndexZ As Integer
Dim iIndexK As Currency
Dim iSum As Currency
Dim iCount As Integer
Dim sStr As String
For iIndexX = 0 To 5
For iIndexY = 0 To 6
For iIndexZ = 0 To 12
For iIndexK = 0 To 13
iSum = iIndexX * 267 + iIndexY * 215 + iIndexZ * 110 + iIndexK * 102.5
If iSum >= 1233 And iSum <= 1355 Then
sStr = sStr & iIndexX & " " & iIndexY & " " & iIndexZ & " " & iIndexK & " " & iSum & vbCrLf
iCount = iCount + 1
End If
Next
Next
Next
Next
Call VB.Clipboard.Clear
Call VB.Clipboard.SetText(sStr)
MsgBox iCount
End Sub
Private Sub CmdRun_Click()
Dim iIndexX As Integer
Dim iIndexY As Integer
Dim iIndexZ As Integer
Dim iIndexK As Currency
Dim iSum As Currency
Dim iCount As Integer
Dim sStr As String
For iIndexX = 0 To 1355 Step 267
For iIndexY = 0 To 1355 Step 215
For iIndexZ = 0 To 1355 Step 110
For iIndexK = 0 To 1355 Step 102.5
iSum = iIndexX + iIndexY + iIndexZ + iIndexK
If iSum >= 1233 And iSum <= 1355 Then
sStr = sStr & (iIndexX / 267) & " " & (iIndexY / 215) & " " & (iIndexZ / 110) & " " & (iIndexK / 102.5) & " " & iSum & vbCrLf
iCount = iCount + 1
End If
Next
Next
Next
Next
Call VB.Clipboard.Clear
Call VB.Clipboard.SetText(sStr)
MsgBox iCount
End Sub
0 0 0 13 1332.5
0 0 1 11 1237.5
0 0 1 12 1340
0 0 2 10 1245
0 0 2 11 1347.5
0 0 3 9 1252.5
0 0 3 10 1355
0 0 4 8 1260
0 0 5 7 1267.5
0 0 6 6 1275
0 0 7 5 1282.5
0 0 8 4 1290
0 0 9 3 1297.5
0 0 10 2 1305
0 0 11 1 1312.5
0 0 12 0 1320
0 1 0 10 1240
0 1 0 11 1342.5
0 1 1 9 1247.5
0 1 1 10 1350
0 1 2 8 1255
0 1 3 7 1262.5
0 1 4 6 1270
0 1 5 5 1277.5
0 1 6 4 1285
0 1 7 3 1292.5
0 1 8 2 1300
0 1 9 1 1307.5
0 1 10 0 1315
0 2 0 8 1250
0 2 0 9 1352.5
0 2 1 7 1257.5
0 2 2 6 1265
0 2 3 5 1272.5
0 2 4 4 1280
0 2 5 3 1287.5
0 2 6 2 1295
0 2 7 1 1302.5
0 2 8 0 1310
0 3 0 6 1260
0 3 1 5 1267.5
0 3 2 4 1275
0 3 3 3 1282.5
0 3 4 2 1290
0 3 5 1 1297.5
0 3 6 0 1305
0 4 0 4 1270
0 4 1 3 1277.5
0 4 2 2 1285
0 4 3 1 1292.5
0 4 4 0 1300
0 5 0 2 1280
0 5 1 1 1287.5
0 5 2 0 1295
0 6 0 0 1290
1 0 0 10 1292
1 0 1 9 1299.5
1 0 2 8 1307
1 0 3 7 1314.5
1 0 4 6 1322
1 0 5 5 1329.5
1 0 6 3 1234.5
1 0 6 4 1337
1 0 7 2 1242
1 0 7 3 1344.5
1 0 8 1 1249.5
1 0 8 2 1352
1 0 9 0 1257
1 1 0 8 1302
1 1 1 7 1309.5
1 1 2 6 1317
1 1 3 5 1324.5
1 1 4 4 1332
1 1 5 2 1237
1 1 5 3 1339.5
1 1 6 1 1244.5
1 1 6 2 1347
1 1 7 0 1252
1 1 7 1 1354.5
1 2 0 6 1312
1 2 1 5 1319.5
1 2 2 4 1327
1 2 3 3 1334.5
1 2 4 1 1239.5
1 2 4 2 1342
1 2 5 0 1247
1 2 5 1 1349.5
1 3 0 4 1322
1 3 1 3 1329.5
1 3 2 1 1234.5
1 3 2 2 1337
1 3 3 0 1242
1 3 3 1 1344.5
1 3 4 0 1352
1 4 0 2 1332
1 4 1 0 1237
1 4 1 1 1339.5
1 4 2 0 1347
1 5 0 0 1342
2 0 0 7 1251.5
2 0 0 8 1354
2 0 1 6 1259
2 0 2 5 1266.5
2 0 3 4 1274
2 0 4 3 1281.5
2 0 5 2 1289
2 0 6 1 1296.5
2 0 7 0 1304
2 1 0 5 1261.5
2 1 1 4 1269
2 1 2 3 1276.5
2 1 3 2 1284
2 1 4 1 1291.5
2 1 5 0 1299
2 2 0 3 1271.5
2 2 1 2 1279
2 2 2 1 1286.5
2 2 3 0 1294
2 3 0 1 1281.5
2 3 1 0 1289
3 0 0 5 1313.5
3 0 1 4 1321
3 0 2 3 1328.5
3 0 3 1 1233.5
3 0 3 2 1336
3 0 4 0 1241
3 0 4 1 1343.5
3 0 5 0 1351
3 1 0 3 1323.5
3 1 1 2 1331
3 1 2 0 1236
3 1 2 1 1338.5
3 1 3 0 1346
3 2 0 1 1333.5
3 2 1 0 1341
4 0 0 2 1273
4 0 1 1 1280.5
4 0 2 0 1288
4 1 0 0 1283
5 0 0 0 1335
※ 引述《apexmilo (失意人)》之铭言:
: 我有一个数学问题
: 267*X+215*Y+110*Z+102.5*K=1233~1355间
: 我想知道有几种组合
: 请问板上高手 有办法写出来吗?
: 请高手大大忙小弟!
楼主: Yaiba (绯心刀刃)   2016-11-05 02:01:00
也还可以加快(虽然现在半秒就跑完了)只要一爆 那层循环就不用跑了如果下层循环为0时就爆了 那这层也不用跑了中间也可以直接算最低的差额用乘的不过在资料量少 条件严苛的这题目 就不用多花时间了
作者: MOONRAKER (㊣牛鹤鳗毛人)   2016-11-05 14:46:00
恭喜你给不把写程式当回事的人当了一次好人 颗

Links booklink

Contact Us: admin [ a t ] ucptt.com