PHP速学视频免费教程(入门到精通)
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
在这里我们会看到一个有趣的问题。假设给定一个大小为 n 的二进制数组。这里n > 3。true值或1值表示活动状态,0或false表示不活动状态。还给出了另一个数字k。我们必须在 k 天后找到活跃或不活跃的细胞。每次之后 如果左右单元格不相同,则第 i 个单元格的白天状态为活动状态,如果相同,则为非活动状态。最左边和最右边的单元格前后没有单元格。因此,最左边和最右边的单元格始终为 0。
让我们看一个示例来了解这一想法。假设一个数组类似于 {0, 1, 0, 1, 0, 1, 0, 1},k 的值 = 3。让我们看看它每天是如何变化的。
所以 2 个活动单元格和 6 个非活动单元格
begin make a copy of arr into temp for i in range 1 to k, do temp[0] := 0 XOR arr[1] temp[n-1] := 0 XOR arr[n-2] for each cell i from 1 to n-2, do temp[i] := arr[i-1] XOR arr[i+1] done copy temp to arr for next iteration done count number of 1s as active, and number of 0s as inactive, then return the values. end
#include <iostream> using namespace std; void activeCellKdays(bool arr[], int n, int k) { bool temp[n]; //temp is holding the copy of the arr for (int i=0; i<n i temp arr value for left cell right all intermediate if and are not same put back the to next iteration active="0," inactive="0;" else cells="<< active <<"></n></iostream>
已抢6730个
抢已抢90968个
抢已抢14329个
抢已抢50415个
抢已抢189734个
抢已抢86092个
抢