bit*_*tan 4 c++ arrays algorithm data-structures
基于 GeeksForGeeks here 中的问题。我在这里遇到了一个解决方案。
有人可以帮助我理解解决方案。主要我需要以下块的帮助:
if(n==1) cout<<arr[0]<<endl;
else if(n%2) {
ll ind = n-3;
ind = floor(ind/4);
ind = 3+ind;
cout<<arr[ind-1]<<endl;
} else {
ll ind = n-2;
ind = floor(ind/4);
ind = 2+ind;
cout<<arr[ind-1]<<endl;
}
Run Code Online (Sandbox Code Playgroud)
小智 5
对于每个大小的数组,一个特定的位置是答案(即 .independent 数组元素)。
对于任何大小为 8 的数组,第 2 个位置(即第 3 个元素)给出了答案。
让我们看一些例子:
等等。
对于偶数:floor( (n-3)/4 )+2给出位置。
对于奇数大小:floor( (n-2)/4 )+1给出位置。
| 归档时间: |
|
| 查看次数: |
1173 次 |
| 最近记录: |