
点击“查找”按钮,查找所有符合要求的正方形。算法思路:枚举正方形对角线上的线段端点A、C(即保证线段AC与x轴呈斜45度的夹角),通过A、C点,计算出正方形另-条对角线上的线段端点B、D,再查找B、D是否存在,若存在,则说明该正方形可以生成。
(1)能够在List1中显示“OK”的语句是
(2)实现上述功能的VB程序如下,请在划线处填入合适的代码。
(3)程序中加框处代码有错,请改正。
Dim n As Integer, x(1000) As Integer, y(1000) As Integer
Private Sub Command2_Click()
’生成n个点的坐标,并按要求排序,代码略
’第i个点的坐标保存在x(i)和y(i)并显示在List1中
End Sub
Private Sub Command2_Click()
Dim i As Integer, j As Integer
For i = 1 To n
For j = i + 1 To n
If

If search(x(i), y(j)) = True And search (
’将4个坐标点显示在List2中,代码略
cnt = cnt + 1
End If
End If
Next j
Next i
List2.AddItem “总共有” + Str(cnt) + “个符合要求的正方形”
End Sub
Function search(sx As Integer, sy As Integer) As Boolean
Dim L As Integer, R As Integer, m As Integer
search = False: L = 1: R = n
Do While L <= R
m = (L + R)\2
If sx < x(m) Or
R = m – 1
ElseIf sx > x(m) Or sx = x(m) And sy > y(m) Then
L = m + 1
Else
Search = True: Exit Do
End If
Loop
End Function

同类型试题

y = sin x, x∈R, y∈[–1,1],周期为2π,函数图像以 x = (π/2) + kπ 为对称轴
y = arcsin x, x∈[–1,1], y∈[–π/2,π/2]
sin x = 0 ←→ arcsin x = 0
sin x = 1/2 ←→ arcsin x = π/6
sin x = √2/2 ←→ arcsin x = π/4
sin x = 1 ←→ arcsin x = π/2


y = sin x, x∈R, y∈[–1,1],周期为2π,函数图像以 x = (π/2) + kπ 为对称轴
y = arcsin x, x∈[–1,1], y∈[–π/2,π/2]
sin x = 0 ←→ arcsin x = 0
sin x = 1/2 ←→ arcsin x = π/6
sin x = √2/2 ←→ arcsin x = π/4
sin x = 1 ←→ arcsin x = π/2

