有没有兄弟可以帮我把这道题帮忙用程序算出来:题目如下。
X*379.08+Y*182.25约等于609526.24
X,Y是整数。误差在1之内。求X,Y的值
谢谢。。
如果X,Y限定是整数的话,最好的情况是:
最终的结果是609524.2 (最终结果误差2)
可以根据表达式看出X的最大值是:1608,Y的最大值是: 3345
此时符合条件的X,Y的值有64组之多(这里应该是全部的解).具体如下:
18,3307 43,3255 68,3203 93,3151 118,3099 143,3047 168,2995 193,2943 218,2891 243,2839
268,2787 293,2735 318,2683 343,2631 368,2579 393,2527 418,2475 443,2423 468,2371 493,2319
518,2267 543,2215 568,2163 593,2111 618,2059 643,2007 668,1955 693,1903 718,1851 743,1799
768,1747 793,1695 818,1643 843,1591 868,1539 893,1487 918,1435 943,1383 968,1331 993,1279
1018,1227 1043,1175 1068,1123 1093,1071 1118,1019 1143,967 1168,915 1193,863 1218,811 1243,759
1268,707 1293,655 1318,603 1343,551 1368,499 1393,447 1418,395 1443,343 1468,291 1493,239
1518,187 1543,135 1568,83 1593,31
算法是最原始的: 枚举
Private Sub Command1_Click()
Dim intI As Long
Dim intJ As Long
Dim intK As Long
Dim intM As Long
Dim SUM As Single
Dim blnHaveResults As Boolean
Dim arySUM(1000, 2)
For intI = 0 To 1608
For intJ = 0 To 3345
SUM = intI * 379.08 + intJ * 182.25
If (SUM >= 609525) And (SUM <= 609528) Then 'Sum的范围如果在609524-609528范围内会得出上面的结果
现在改成609525-609528,就需要把intI ,intJ 的范围放大才能看是
否能够算出相应的解
blnHaveResults = True
arySUM(intK, 0) = intI
arySUM(intK, 1) = intJ
arySUM(intK, 2) = SUM
Text1.Text = Text1.Text & arySUM(intK, 0) & "," & arySUM(intK, 1) & " "
intK = intK + 1
intM = intM + 1
If intM = 10 Then
Text1.Text = Text1.Text & vbCrLf
intM = 0
End If
End If
Next intJ
Next intI
If blnHaveResults <> True Then
MsgBox "No Value"
End If
End Sub
[此贴子已经被作者于2007-2-5 9:42:09编辑过]