【题意】
【解题方法】构造!SPJ!
【代码】
//
//Created by just_sort 2016/10/28
//Copyright (c) 2016 just_sort.All Rights Reserved
//
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
using namespace __gnu_pbds;
typedef long long LL;
typedef pair<int, LL> pp;
#define MP(x,y) make_pair(x,y)
const int maxn = 200005;
const int N = 1005;
const int M = 2010;
const int inf = 0x3f3f3f3f;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>order_set;
//head
//ural 1979
int n, mp[1300][1300];
int main()
{
cin>>n;
int num = 1;
//1
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
mp[3*n-i+1][j] = 6*n*n-num+1;
mp[i][j] = num++;
}
}
for(int i = n+1; i <= n*2; i++)
{
for(int j = 1; j <= n; j++)
{
mp[i][n*3-j+1] = 6*n*n-num+1;
mp[i][j] = num++;
}
for(int j = n+1; j <= 2*n; j++)
{
mp[i][n*5-j+1] = 6*n*n-num+1;
mp[i][j] = num++;
}
}
//2
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
printf("%d%c",mp[i][j],j==n?'\n':' ');
}
}
for(int i = n+1; i <= n*2; i++)
{
for(int j = 1; j <= n*4; j++)
{
printf("%d%c",mp[i][j],j==n*4?'\n':' ');
}
}
for(int i = n*2 + 1; i <= n*3; i++)
{
for(int j = 1; j <= n; j++)
{
printf("%d%c",mp[i][j],j==n?'\n':' ');
}
}
}
本文提供了一个构造算法题目的解题思路及实现代码。利用特定的数据结构和算法技巧完成了一个复杂构造题目,通过精心设计的数据填充策略实现了题目的要求。
134

被折叠的 条评论
为什么被折叠?



