2024.12.19 周四
2024.12.19 周四
Q1. 1000
Consider a
A path is a sequence of cells achieved by starting at
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
Construct a way to place the integers
Q2. 1000
Conveyor matrix
In other words, the conveyor matrix for
The conveyor matrix
You are standing in a cell with coordinates
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
For example,
------------------------独自思考分割线------------------------
-
用时:30(-1) 25,第三道没出..
A1.
A2.
- 本质就是求两环的距离,以中间的环(4个正方形)作为参考计算相对距离,差就是答案。
- 求相对距离时灵光一现发现:
。 - 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;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!