给你一个n*n的方格,每个方格里的数必须连续摆放如
1
2
4
3
,下图为不连续的,请输出从左上角到右下角的对角线上的最大和
123
1619
n=1
1
n=2
2 1
3 4 //4 2
n=3
3 2 1
4 7 8
5 6 9 //9 7 3(7/2)
5
15 16 17 18 1914 13 22 21 2011 12 23 2 110 25 24 3 49 8 7 6 5 // 25 23 21 19 9(19/2)
规律:等差k-1项+最后一项/2
#include #include #include #include #include using namespace std;int main(void){//freopen("题.txt", "r", stdin);int n;long long sum;while (scanf("%d", &n) != EOF){int k = n * n;sum = 0;for(int i = 1; i }