zoj 3823 Excavator Contest 构造
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次
题解:
分奇数偶数构造
大概偶数特别容易想
奇数比较麻烦,奇数在我的构造方式下,要转圈圈

反正就非常迷就是了……
@)1%KBO0HM418$J94$1R.jpg)
代码:
//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 构造的更多相关文章
- zoj 3823 Excavator Contest(结构体)
题目链接:zoj 3823 Excavator Contest 题目大意:一个人开着挖掘机要在N*N的格子上面移动.要求走全然部的格子.而且转完次数要至少为n*(n-1) - 1次, 而且终点和起点必 ...
- ACM-ICPC 2018 青岛赛区现场赛 D. Magic Multiplication && ZOJ 4061 (思维+构造)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4061 题意:定义一个长度为 n 的序列 a1,a2,..,an ...
- 【ZOJ 3502】Contest
题 题意 n个问题,解决的顺序影响正确的概率,无论之前解决的问题是否答对,当前问题 j 答对概率为max{a[i][j]} (i为解决过的问题).求答对题目的最大期望和对应的答题顺序.T组测试,T ( ...
- zoj 3212 K-Nice(构造)
K-Nice Time Limit: 1 Second Memory Limit: 32768 KB Special Judge This is a super simple pr ...
- ZOJ 2334 Monkey King
并查集+左偏树.....合并的时候用左偏树,合并结束后吧父结点全部定成树的根节点,保证任意两个猴子都可以通过Find找到最厉害的猴子 Monkey King ...
- 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 ...
- 2014ACM/ICPC亚洲区牡丹江站 浙大命题
A Average Score http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5373 a班有n个人,b班有m个人,bob在a ...
- 2014 牡丹江区域赛 B D I
http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=358 The 2014 ACM-ICPC Asia Mudanj ...
- ZOJ 3212 K-Nice(满足某个要求的矩阵构造)
H - K-Nice Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit Sta ...
随机推荐
- BZOJ3509: [CodeChef] COUNTARI
3509: [CodeChef] COUNTARI Time Limit: 40 Sec Memory Limit: 128 MBSubmit: 339 Solved: 85[Submit][St ...
- CF GYM 100703G Game of numbers
题意:给n个数,一开始基数为0,用这n个数依次对基数做加法或减法,使基数不超过k且不小于0,输出最远能运算到的数字个数,输出策略. 解法:dp.dp[i][j]表示做完第i个数字的运算后结果为j的可能 ...
- android studio 使用的一些注意,一些报错的解决方法(原创)
NDK 编译无法通过 注意看 build.gradle 里面的 有些是 ndk-build windows 上用 ndk-build.cmd Summary: gradle calls ndk-bui ...
- HDU 5607 graph 矩阵快速幂 + 快速幂
这道题得到了学长的助攻,其实就是一个马尔科夫链,算出一步转移矩阵进行矩阵快速幂就行了,无奈手残 这是我第一回写矩阵快速幂,写的各种毛病,等到调完了已经8点44了,交了一发,返回PE,(发现是少了换行) ...
- Testlink & Redmine组合拳演练
环境:Ubuntu 14.04LTS 一.部署testlink 查看已安装软件: dpkg -l *apache* (apache2.4.7) dpkg -l *php* (未安装) dpkg -l ...
- HGE初始化状态设置
HGE_FRAMEFUNC: 最重要的设置,每个HGE应用必须设置.游戏的主循环就是他了.类型为bool*(),返回真那么主循环退出,游戏也就结束了.否则进行必要的处理后返回假.必须在调用进入 ...
- Vijos1404 遭遇战 最短路,dijkstra,堆
P1404遭遇战 标签:[显示标签] 背景 你知道吗,SQ Class的人都很喜欢打CS.(不知道CS是什么的人不用参加这次比赛). 描述 今天,他们在打一张叫DUSTII的地图,万恶的恐怖分 ...
- Polymorphism
多态定义(百度百科):多态(Polymorphism)按字面的意思就是“多种状态”.在面向对象语言中,接口的多种不同的实现方式即为多态.引用Charlie Calverts对多态的描述 ——多态性是允 ...
- ubuntu openstack spice
Openstack启用spice协议 #控制节点 #安装 ? 1 apt-get install nova-spiceproxy spice-html5 spice-vdagent #配置 nano ...
- 二叉搜索树算法详解与Java实现
二叉查找树可以递归地定义如下,二叉查找树或者是空二叉树,或者是满足下列性质的二叉树: (1)若它的左子树不为空,则其左子树上任意结点的关键字的值都小于根结点关键字的值. (2)若它的右子树不为空,则其 ...