序号 | 姓名 | 班级 | 测量时间 | 体温(℃) | 是否去过高风险地区 |
1 | 张三 | 高一(3) | 7:23 | 36.8 | 否 |
2 | 李四 | 高二(5) | 7:31 | 36.9 | 否 |
… | … | … | … | … | … |
下列描述正确的是( )
k=0:n=Len(s)
For i = 1 To n\2
k = k+Abs(Asc(Mid(s,i,1)) - Asc(Mid(s,n-i+1,1)))
Next i
If k=0 Then flag=True
运行后该程序段后,变量flag的值为True,s的值可能的是( )
i = 1: L = 0: R = n + 1
Do While i < R
If a(i) < k1 Then
L = L + 1
If L <> i Then tt = a(i): a(i) = a(L): a(L) = tt
i = i + 1
ElseIf a(i) > k2 Then
R = R - 1
tt = a(i): a(i) = a(R): a(R) = tt
Else
i = i + 1
End If
Loop
则执行上述代码后,下列说法正确的是( )
s = "happy": n = Len(s)
For i = 1 To n
x = Int(Rnd * n + 1)
c = Mid(s, x, 1)
If x Mod 2 = 0 Then
c = Chr((Asc(c) - Asc("a") + 1) Mod 26 + Asc("a"))
Else
c = Chr(Asc("a") + 25 - (Asc(c) - Asc("a")))
End If
s1 = c + s1
Next i
则运行本程序段后,变量s1的值不可能为( )
i=1:j=n
Do While i<j
m=(i+j)\2
If ① Then
i=m+ 1
Else
②
End If
Loop
Ifa(i)=key Then Label1.Caption=Str(i) Else Label1.Caption="找不到"
上述程序段两个横线处的语句分别为( )
图a
图b |
图c |
图d |
图e |
如上图所示的棋盘,需要选择第2行第2列、第4行第2列两颗棋子,按照规则进行翻转便可使得棋盘变为纯黑。现编写程序找出实现棋盘纯色所需翻转棋子次数最少的方案并输出所挑选棋子的个数,若无答案则输出“无法翻转为纯色”。
解决该问题的算法原理:棋盘翻转方案为0000000000000000~1111111111111111之间的某几种,即十进制数 0~65535,利用枚举算法在0~65535之间枚举,即可找到最优方案。假设被选翻转棋子状态用1表示被选中,0表示不选中。例如某方案的十进制为1028即 2^10+2^2,转化为一个16位的二进制串0000010000000100就表示该棋盘中的第2行第2列、第4行第2列这两个棋子及其上下左右被选中翻转,我们认为该方案选中两个棋子进行翻转。
程序运行界面如下图所示,请回答下列问题。
'数组a储存棋盘原状态,数组b储存翻转后的棋盘状态
Dim a(1 To 16) As Integer, b(1 To 16) As Integer, minc As Long
Private Sub Form_Load()
'生成原始由0、1组成的棋盘状态,用数组 a(1)-a(16)保存,代码略
End Sub
Private Sub Command1_Click()
Dim k As Integer, c As Integer, i As Long, j As Long
minc = 100
For i = 0 To 65535
For j = 1 To 16 '初始化棋盘
b(j) = a(j)
Next j
k = 16: c = 0: j = i
Do While j > 0
If j Mod 2=1 Then
b(k) = 1 - b(k)
If k > 4 Then b(k - 4) = 1 - b(k - 4)
If Then b(k + 4) = 1 - b(k + 4)
If k Mod 4 <> 0 Then b(k + 1) = 1 - b(k + 1)
If k Mod 4 <> 1 Then b(k - 1) = 1 - b(k - 1)
c = c + 1
End If
k = k - 1
Loop
If Then minc = c
Next i
If minc = 100 Then Label1.Caption = "无法翻转为纯色!" Else Label1.Caption = "最少翻" + Str(minc) + "次"
End Sub
Function check() As Boolean '判断棋盘是否纯色
Dim flag As Boolean, i As Integer
flag = True
For i = 1 To 15
If Then flag = False: Exit For
Next i
check = flag
End Function
Const n=640 '参加统测总学生数
Const nc =16 '班级数
Dim class(1 To n) As Integer, sname(1 To n)As String, score(1 To n) As Integer
Dim b( To nc) As Integer '存储每个班级的参加统测人数
Dim c(1 To nc) As Integer
Dim d(1 To n)As Integer
Private Sub Form_Load()
'本过程读取每个参加统测学生的班级序号、姓名和统测成绩分别存储在数组class,sname和 score中并在List1中显示,代码略
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer
For i = 1 To nc
b(i) = 0
Next i
For i = 1 To n '统计每个班级统测人数
Next i
k = 1
For i = 1 To nc
c(i) = k
k = k + b(i)
Next i
For i = 1 To n
k = class (i)
c(k) = c(k) + 1
Next i
For i = 1 To nc '对各班级按统测成绩进行排序
Call px(),c(i)-1))
Next i
For i = 1 To n
List2.AddItem " " & class(d(i)) & " "& sname (d(i)) & " " & score(d(i))
Next i
End Sub
Private Sub px(head As Integer, tail As Integer)
Dim i As Integer, j As Integer, t As Integer
For i = head To tail - 1
For j = tail To i + 1 Step -1
If Then
t = d(j): d(j) = d(j - 1): d(j - 1) = t
End If
Next j
Next i
End Sub