ZOJ 3823 Excavator Contest (2014 Mudanjiang Regional E) (构造)

本文介绍了一个关于路径规划的问题,即如何让一台挖掘机在一个N×N的方格场地中,从一个边界块开始并最终到达另一个边界块,在此过程中每个方格只能被访问一次,并尽可能多地转弯,展示了奇数和偶数情况下具体的构造方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Excavator Contest

Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge

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).

An excavator

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
Hints

route for N=3 or N=4


Author: ZHOU, Yuchen
Source: The 2014 ACM-ICPC Asia Mudanjiang Regional Contest

    解题报告:构造。

    现场赛时冠军队弄出来了,也是NB到不行。当时我在弄这题,到比赛结束时才发现有起点和终点必须在边界上的限制……

    不过就算是这样,构造方法还是很难想。偶数的构造法如下:

    

    奇数的我一直想不出来,看了其他大神的做法,如下:

    

    整体是中心对称的,可以认为这张图左边少了两列。按照这种方式每次加上两行、两列,可以构造出所有奇数的情况。

    ok,然后就是编码了。偶数很好写,奇数可以预处理,然后根据n的大小打印需要的部分。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <iomanip>
#include <cassert>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define ff(i, n) for(int i=0;i<(n);i++)
#define fff(i, n, m) for(int i=(n);i<=(m);i++)
#define dff(i, n, m) for(int i=(n);i>=(m);i--)
#define travel(e, u) for(int e = u, v = vv[u]; e; e = nxt[e], v = vv[e])
#define bit(n) (1LL<<(n))
#define And(a, b) ((a) & (b))
#define Or(a, b) ((a) | (b))
#define Xor(a, b) ((a) ^ (b))
#define clr(a, b) memset((a), b, sizeof(a))
#define ls (pos<<1)
#define rs (ls|1)
#define lson l, m, ls
#define rson m+1, r, rs
#define mid ((l+r)/2)
typedef long long LL;
typedef unsigned long long ULL;
void work();
int main()
{
#ifdef ACM
    freopen("in.txt", "r", stdin);
#endif // ACM

    work();
    return 0;
}

void scanf(int & x, char ch = 0)
{
    while((ch=getchar()) < '0' || ch > '9');

    x = ch - '0';
    while((ch=getchar()) >= '0' && ch <= '9') x = x * 10 + ch - '0';
}

/***************************************************************************************/

namespace Even
{
int arr[555][555];
int x, y, idx;

void u()
{
    arr[--x][y] = ++idx;
}

void d()
{
    arr[++x][y] = ++idx;
}

void l()
{
    arr[x][--y] = ++idx;
}

void r()
{
    arr[x][++y] = ++idx;
}

void dd()
{
    r(), d(), l(), d();
}

void rr()
{
    d(), r(), u(), r();
}

void ll()
{
    l(), u(), l(), d();
}

void uu()
{
    u(), l(), u(), r();
}
}

namespace Odd
{
int arr[1111][1111];
int x, y, idx;

void u()
{
    arr[--x][y] = ++idx;
    arr[1000-x][1000-y] = -arr[x][y];
}

void d()
{
    arr[++x][y] = ++idx;
    arr[1000-x][1000-y] = -arr[x][y];
}

void l()
{
    arr[x][--y] = ++idx;
    arr[1000-x][1000-y] = -arr[x][y];
}

void r()
{
    arr[x][++y] = ++idx;
    arr[1000-x][1000-y] = -arr[x][y];
}

void dd()
{
    r(), d(), l(), d();
}

void rr()
{
    d(), r(), u(), r();
}

void ll()
{
    l(), u(), l(), d();
}

void uu()
{
    u(), r(), u(), l();
}
}

void init()
{
    using namespace Odd;

    x = 500, y = 500, idx = 0;
    clr(arr, 0x7F);

    arr[x][y] = idx;
    u(), r();

    fff(i, 1, 256) if(i%4 == 1)
    {
        ff(j, i) dd();
        r(), d(), d();
    }
    else if(i%4 == 2)
    {
        ff(j, i) ll();
        l(), l();
    }
    else if(i%4 == 3)
    {
        ff(j, i) uu();
        u(), u(), r();
    }
    else if(i%4 == 0)
    {
        ff(j, i) rr();
    }
}

void work()
{
    init();

    int T;
    scanf("%d", &T);

    fff(cas, 1, T)
    {
        int n;
        scanf("%d", &n);

        if(n == 1)
        {
            puts("1");
        }
        else if(n == 2)
        {
            puts("1 2");
            puts("4 3");
        }
        else if(n == 3)
        {
            puts("1 2 3");
            puts("8 7 4");
            puts("9 6 5");
        }
        else if(n%2 == 0)
        {
            using namespace Even;
            x = 1, y = 1, idx = 0;
            arr[x][y] = ++idx;

            int stp = n/2 - 1;

            fff(i, 1, (n+2)/4)
            {
                ff(j, stp) dd();
                rr();
                d(), r(), u();
                ff(j, stp) uu();
                r();
            }

            fff(i, 1, n) fff(j, 1, n)
            {
                printf("%d", arr[i][j]);
                if(j == n)
                    puts("");
                else
                    printf(" ");
            }
        }
        else
        {
            using namespace Odd;

            int t = (n * (n+2) - 1) / 2;

            int xx, yy;
            ff(i, 1111) ff(j, 1111) if(arr[i][j] == t)
                xx = i, yy = j;
            xx = min(xx, 1000-xx);
            yy = min(yy, 1000-yy);

            int mi = 1<<30;
            fff(i, xx, xx+n-1) fff(j, yy, yy+n-1)
                mi = min(mi, arr[i][j]);

            fff(i, xx, xx+n-1) fff(j, yy, yy+n-1)
            {
                printf("%d", arr[i][j] - mi + 1);
                if(j == yy+n-1)
                    puts("");
                else
                    printf(" ");
            }
        }
    }
}



内容概要:本文详细介绍了名为MoSca的系统,该系统旨在从单目随意拍摄的视频中重建和合成动态场景的新视角。MoSca通过4D Motion Scaffolds(运动支架)将视频数据转化为紧凑平滑编码的Motion Scaffold表示,并将场景几何和外观与变形场解耦,通过高斯融合进行优化。系统还解决了相机焦距和姿态的问题,无需额外的姿态估计工具。文章不仅提供了系统的理论背景,还给出了基于PyTorch的简化实现代码,涵盖MotionScaffold、GaussianFusion、MoScaSystem等核心组件。此外,文中深入探讨了ARAP变形模型、2D先验到3D的提升、动态高斯表示、相机参数估计等关键技术,并提出了完整的训练流程和性能优化技巧。 适用人群:具备一定计算机视觉和深度学习基础的研究人员和工程师,特别是对动态场景重建和新视角合成感兴趣的从业者。 使用场景及目标:①从单目视频中重建动态场景的新视角;②研究和实现基于4D Motion Scaffolds的动态场景表示方法;③探索如何利用预训练视觉模型的先验知识提升3D重建质量;④开发高效的动态场景渲染和优化算法。 其他说明:本文提供了详细的代码实现,包括简化版和深入扩展的技术细节。阅读者可以通过代码实践加深对MoSca系统的理解,并根据具体应用场景调整和扩展各个模块。此外,文中还强调了物理启发的正则化项和多模态先验融合的重要性,帮助实现更合理的变形和更高质量的渲染效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值