题目:![](https://img-blog.csdnimg.cn/2dd312a2551741d68ca4ded00124ea0b.png)
|
1 2 4 3 5 1 2 1 2 3 6 4 5 7 1 2 3 4 8 5 10 6 9 7 |
解题思路:
思维,找规律题,看样例,就是当前的一个数是后面一个数的两倍。太难了,哭死(;´༎ຶД༎ຶ`)
代码详解如下:
#include <iostream>
#define endl '\n'
#pragma GCC optimize(3,"Ofast","inline")
#define ___G std::ios::sync_with_stdio(false),cin.tie(0), cout.tie(0)
using namespace std;
const int N = 2e6 + 10;
inline void solve()
{
int n;
cin >> n;
for (int i = 1; i <= n; i += 2) // 这里 i += 2 是跨越一个数
{
for (int j = i; j <= n; j <<= 1) // 这里实际是 j *= 2
{
cout << j << ' ';
}
}
cout << endl;
}
int main()
{
___G;
// freopen("a.txt", "r", stdin);
int _t = 1;
cin >> _t;
while (_t--)
{
solve();
}
return 0;
}
最后提交: