40 lines
843 B
C++
40 lines
843 B
C++
#include <bits/stdc++.h>
|
||
|
||
using namespace std;
|
||
const int N = 110;
|
||
int a[N];
|
||
#define x first
|
||
#define y second
|
||
typedef pair<int, int> PII;
|
||
|
||
int main() {
|
||
int cnt = 0;
|
||
a[1] = ++cnt, a[128] = ++cnt;
|
||
|
||
queue<PII> q;
|
||
q.push({1, 128});
|
||
|
||
while (q.size()) {
|
||
auto t = q.front();
|
||
q.pop();
|
||
int mid = (t.x + t.y) >> 1;
|
||
a[mid] = ++cnt, a[mid + 1] = ++cnt;
|
||
if (cnt > 32) break;
|
||
q.push({t.x, mid});
|
||
q.push({mid + 1, t.y});
|
||
}
|
||
|
||
cnt = 0;
|
||
for (int i = 1; i <= 128; i++) {
|
||
if (a[i]) {
|
||
cnt++;
|
||
printf("a[%d]=%d ", i, a[i]);
|
||
if (cnt % 5 == 0) printf("\n");
|
||
}
|
||
}
|
||
// 1肯定是1,2肯定是128
|
||
// 3可能是64,也可能是65
|
||
// 4可能是64,也可能是65
|
||
|
||
return 0;
|
||
} |