2018年东北农业大学春季校赛 B wyh的矩阵【规律】

https://www.nowcoder.com/acm/contest/93/B

AC代码

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits>

#define CLR(a) memset(a, 0, sizeof(a))
#define pb push_back

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss;

const double PI = 3.14159265358979323846264338327;
const double E = exp(1);
const double eps = 1e-30;

const int INF = 0x3f3f3f3f;
const int maxn = 1e4 + 5;
const int MOD = 1e9 + 7;

int main()
{
int T;
scanf("%d", &T);
while (T--)
{
int n;
scanf("%d", &n);
ll ans = 0;
int mid = n / 2 + 1;
for (int i = 1; i <= n; i++)
ans += (mid - 1) * n + i + (i - 1) * n + mid;
ans -= (mid - 1) * n + mid;
for (int i = 2, j = 1; i < mid; i++, j++)
{
for (int k = 0; k < j; k++)
{
ans += 2 * ((i - 1) * n + mid);
}
}
for (int i = n - 1, j = 1; i > mid; i--, j++)
{
for (int k = 0; k < j; k++)
ans += 2 * ((i - 1) * n + mid);
}
printf("%lld\n", ans);
}
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120