2024.12.19 周四

2024.12.19 周四


Q1. 1000

Consider a 2×n grid, where n is an even integer. You may place the integers 1,2,,2n on the grid, using each integer exactly once.

A path is a sequence of cells achieved by starting at (1,1), then repeatedly walking either downwards or to the right, and stopping when (2,n) is reached. The path should not extend beyond the grid.

The cost of a path is the alternating sum of the numbers written on the cells in a path. That is, let the numbers written on the cells be a1,a2,,ak (in the order that it is visited), the cost of the path is a1a2+a3a4+=i=1kai(1)i+1.

Construct a way to place the integers 1,2,,2n on the grid, such that the minimum cost over all paths from (1,1) to (2,n) is maximized. If there are multiple such grids that result in the maximum value, output any of them.

Q2. 1000

Conveyor matrix mn is matrix of size n×n, where n is an even number. The matrix consists of concentric ribbons moving clockwise.

In other words, the conveyor matrix for n=2 is simply a matrix 2×2, whose cells form a cycle of length 4 clockwise. For any natural k2, the matrix m2k is obtained by adding to the matrix m2k2 an outer layer forming a clockwise cycle.


The conveyor matrix 8×8.

You are standing in a cell with coordinates x1,y1 and you want to get into a cell with coordinates x2,y2. A cell has coordinates x,y if it is located at the intersection of the xth row and the yth column.

Standing on some cell, every second you will move to the cell next in the direction of movement of the tape on which you are. You can also move to a neighboring cell by spending one unit of energy. Movements happen instantly and you can make an unlimited number of them at any time.

Your task is to find the minimum amount of energy that will have to be spent to get from the cell with coordinates x1,y1 to the cell with coordinates x2,y2.

For example, n=8 initially you are in a cell with coordinates 1,3 and you want to get into a cell with coordinates 6,4. You can immediately make 2 movements, once you are in a cell with coordinates 3,3, and then after 8 seconds you will be in the right cell.

------------------------独自思考分割线------------------------

  • 用时:30(-1) 25,第三道没出..

A1.

  1. 又一道好的构造,证明较难。

A2.

  1. 本质就是求两环的距离,以中间的环(4个正方形)作为参考计算相对距离,差就是答案。
  2. 求相对距离时灵光一现发现:min(4max(dx,dy))
  3. coordinates 坐标

------------------------代码分割线------------------------

A1.

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(6);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    int n;
    cin >> n;
    cout << n * 2 - 1 << ' ';
    int l = 1, r = n * 2 - 3;
    int f = 1;
    for (int i = 2; i <= n; i++)
    {
        if (f)
            cout << l << ' ', l += 2;
        else
            cout << r << ' ', r -= 2;
        f ^= 1;
    }
    cout << endl;
    l = 2, r = n * 2 - 2;
    f = 1;
    for (int i = 1; i < n; i++)
    {
        if (f)
            cout << l << ' ', l += 2;
        else
            cout << r << ' ', r -= 2;
        f ^= 1;
    }
    cout << n * 2 << endl;
}

A2.

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(6);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    int n, x1, y1, x2, y2;
    cin >> n >> x1 >> y1 >> x2 >> y2;
    n >>= 1;
    auto get = [&](int x, int y)
    {
        int dx[] = {n, n, n + 1, n + 1}, dy[] = {n, n + 1, n + 1, n};
        int res = 1e12;
        for (int i = 0; i < 4; i++)
            res = min(res, max(abs(x - dx[i]), abs(y - dy[i]))); // 灵机一动
        // bug2(x, y);
        // bug(res);
        return res;
    };
    cout << abs(get(x1, y1) - get(x2, y2)) << endl;
}
posted @   Jkke  阅读(2)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
点击右上角即可分享
微信分享提示