蓝桥杯-2020-B组 · 题解/解析(4/17)

因为 明天 就 竞赛了,所以 先写一下 蛇形填数 那道题,我自己 写出来的 一个 比较 优的解!

#include <iostream>
using namespace std;
int a[40];
int main()
{
    a[0] = 1;
	for(int i = 1;i<40;++i)
    {
        if(i%2==0)
        {
            a[i] = a[i-1] + (i/2)*4;
        }
        else{
            a[i] = a[i-1] + 1;
        }
        
    }
    cout << a[39] - 20 <<endl;
	return 0;
}
原文地址:https://www.cnblogs.com/MuQuanyu-YuGod/p/14671930.html