Excavator Contest

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3823

Description

Bluefly University is famous of excavator technology. Lots of students take part in many excavator-related courses. After the students finish their courses, they will compete in a contest called International Collegiate Excavator Contest (ICEC).

This year's ICEC will be held at Marjar University. This is an individual competition that each contestant will start the match one by one.

The task of the contest is to drive an excavator passing a square field. The judge partitioned the field into N × N equal-sized square chunks. Each chunk should be visited exactly one time. The contestant will drive the excavator, starting from and ending at the center of two different boundary chunks.

In order to show off their superb excavator operating skills, the contestants need to drive the excavator with as many as possible turnings. Since the excavator is a kind of large and heavy vehicle, it can only make a turn to left or right at the center of any chunk.

Bob is a student from Marjar University. He wants to win the contest. To fulfill this dream, he needs to drive the excavator with at least N× (N - 1) - 1 turnings. It seems to be a difficult task, so he turns to you for help. Please write a program to find a feasible route for him.

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

There is only one integer N (2 <= N <= 512).

Output

For each test case, output a matrix with N × N integers indicating the route to pass all the chunks. Bob will drive the excavator passing the chunks in the order of 1, 2, .., N2.

If there are multiple solutions, any one will be acceptable.

Sample Input

2
4
3
 

Sample Output

2 1 16 15
3 4 13 14
6 5 12 11
7 8 9 10
1 2 3
8 7 4
9 6 5

HINT

题意

给你一个n*n个格子,然后让你跑,使得起点和终点都必须在边界上

而且使得转弯次数至少是n*(n-1)-1次

题解:

分奇数偶数构造

大概偶数特别容易想

奇数比较麻烦,奇数在我的构造方式下,要转圈圈

反正就非常迷就是了……

代码:

//qscqesze
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100006
#define mod 1000000007
#define eps 1e-9
#define e exp(1.0)
#define PI acos(-1)
const double EP = 1E- ;
int Num;
//const int inf=0x7fffffff;
const ll inf=;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************* int A[][];
int B[][];
int main()
{
int t;scanf("%d",&t);
while(t--)
{
int n;scanf("%d",&n);
if(n%==)
{
int nowx= ,nowy = ;
int now = ;
while(now<=n*n)
{
A[nowy][nowx]=now;
if(nowy<=n-)
{
if(nowx%==)
{
if(nowy%==)
nowx=nowx+;
else
nowy=nowy+;
}
else if(nowx%==)
{
if(nowy%==)
nowy=nowy+;
else
nowx=nowx-;
}
else if(nowx%==)
{
if(nowy%==)
nowx=nowx+;
else
nowy=nowy-;
}
else
{
if(nowy==)
nowx=nowx+;
else if(nowy%==)
nowy=nowy-;
else
nowx=nowx-;
}
}
else
{
if(nowx%==)
{
if(nowy==n-)
nowy=nowy+;
else
nowx=nowx+;
}
else if(nowx%==)
{
if(nowy==n-)
nowx=nowx+;
else
nowy=nowy-;
}
else if(nowx%==)
{
if(nowy==n-)
nowy=nowy+;
else
nowx=nowx+;
}
else
{
nowy=nowy-;
}
}
now++;
}
}
else
{
A[][]=;
int nowx = ;
int nowy = ;
int now = ;
for(int i=;i<=n;i+=)
{
for(int ii=;ii<=i-;ii++)
{
for(int jj=;jj<=i-;jj++)
{
B[ii][jj]=A[ii][jj];
}
} for(int ii=;ii<=i-;ii++)
{
for(int jj=;jj<=i-;jj++)
{
A[ii][jj]=(i-)*(i-)+-B[i--jj][ii];
}
}
nowx = ,nowy = i-;
while(now<=i*i)
{
A[nowx][nowy]=now;
if(nowx<=i-)
{
if(nowx%==)
{
if(nowy==i-)
nowy=nowy+;
else
nowx=nowx+;
}
else
{
if(nowy==i)
nowy=nowy-;
else
nowx=nowx+;
}
}
else
{
if(nowx==i-)
{
if(nowy%==)
nowy=nowy-;
else
nowx=nowx+;
}
else
{
if(nowy%==)
nowx=nowx-;
else
nowy=nowy-;
}
}
now++;
} }
}
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
printf("%d ",A[i][j]);
}
printf("\n");
}
}
}

zoj 3823 Excavator Contest 构造的更多相关文章

  1. zoj 3823 Excavator Contest(结构体)

    题目链接:zoj 3823 Excavator Contest 题目大意:一个人开着挖掘机要在N*N的格子上面移动.要求走全然部的格子.而且转完次数要至少为n*(n-1) - 1次, 而且终点和起点必 ...

  2. ACM-ICPC 2018 青岛赛区现场赛 D. Magic Multiplication && ZOJ 4061 (思维+构造)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4061 题意:定义一个长度为 n 的序列 a1,a2,..,an ...

  3. 【ZOJ 3502】Contest

    题 题意 n个问题,解决的顺序影响正确的概率,无论之前解决的问题是否答对,当前问题 j 答对概率为max{a[i][j]} (i为解决过的问题).求答对题目的最大期望和对应的答题顺序.T组测试,T ( ...

  4. zoj 3212 K-Nice(构造)

    K-Nice Time Limit: 1 Second      Memory Limit: 32768 KB      Special Judge This is a super simple pr ...

  5. ZOJ 2334 Monkey King

    并查集+左偏树.....合并的时候用左偏树,合并结束后吧父结点全部定成树的根节点,保证任意两个猴子都可以通过Find找到最厉害的猴子                       Monkey King ...

  6. The 2014 ACM-ICPC Asia Mudanjiang Regional Contest

    The 2014 ACM-ICPC Asia Mudanjiang Regional Contest A.Average Score B.Building Fire Stations C.Card G ...

  7. 2014ACM/ICPC亚洲区牡丹江站 浙大命题

    A  Average Score http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5373 a班有n个人,b班有m个人,bob在a ...

  8. 2014 牡丹江区域赛 B D I

    http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=358 The 2014 ACM-ICPC Asia Mudanj ...

  9. ZOJ 3212 K-Nice(满足某个要求的矩阵构造)

    H - K-Nice Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Sta ...

随机推荐

  1. Vs 引用第三方DLL文件 版本不一致问题 (npoi与memcached中的ICSharpCode.SharpZipLib版本冲突的解决方案)

    最近在 做 MailChimp 与网站功能 集成时,发现 MailChimp 2API 中的 MailChimp.dll  中的依赖项 SerivceStack.Text.dll (版本为3.9.71 ...

  2. 中国Azure媒体服务RESTAPI的Endpoint

    Amber Zhao  Thu, Feb 26 2015 4:09 AM 由于海外Azure和中国Azure有不同的domain,很多用户在使用媒体服务RESTAPI时,需要指定中国Azure媒体服务 ...

  3. Java [leetcode 18]4Sum

    问题描述: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d ...

  4. win2003 多域名绑定一个ip

    一个IP绑定多个域名 很多虚拟主机,只有一个IP,很多个域名都指向该IP,但都能访问自己域名所在 的网站的内容,这就是一个IP绑定多个域名的技术. 我们得先了解一个概念 什么是主机头所谓的主机头的叫法 ...

  5. 我的WCF之旅(3):在WCF中实现双工通信

    双工(Duplex)模式的消息交换方式体现在消息交换过程中,参与的双方均可以向对方发送消息.基于双工MEP消息交换可以看成是多个基本模式下(比如请求-回复模式和单项模式)消息交换的组合.双工MEP又具 ...

  6. C# 中的数组(array)

    原文 C# 中的数组(array) 特性 数组是一个无序的元素序列.数组元素存储在一个连续性的内存块中,并可使用一个整数索引来访问. C# 声明数组变量时,数组的大小不是声明的一部分.这点与C/C++ ...

  7. Spring注释@Qualifier

    在学习@Autowired的时候我们已经接触到了@Qualifier, 这节就来详细学习一下自定义@Qualifier. 例如定义一个交通工具类:Vehicle,以及它的子类Bus和Sedan. 如果 ...

  8. jvm 漫谈 笔记

    1.Jvm到底是什么呢? Jvm其实就是模拟一台计算机,每种cpu都有自己的指令集,jvm自己设置一套指令集,这就是我满看的的字节码,然后jvm需要执行这些字节码,其实这些字节码最终直接对应到cpu的 ...

  9. ffmpeg常见命令

    一.安装       下载ffmpeg,解压之后配置环境变量即为安装 打开dos界面,进入目标文件夹例如:E:/ cd E:\BaiduYunDownload\ffmpeg\ffmpeg_simple ...

  10. 3.1 全局存储带宽与合并访问 -- Global Memory(DRAM) bandwidth and memory coalesce

    全局存储带宽(DRAM) 全局内存是动态随机访问的方式访问内存.我们希望访问DRAM的时候非常快,实际情况是DRAM中出来的数据非常非常慢,这就好比,理想状态是泄洪,水倾巢而出,气势宏伟,实际取水却像 ...