用 Python 解决的:
def calculate_final_positions(n, m, movements, start_positions):
# 计算最终位置
final_positions = []
for x, y in start_positions:
for dx, dy in movements:
x += dx
y += dy
final_positions.append((x, y))
return final_positions
# 示例输入
n, m = 3, 2 # 移动次数和点的数量
movements = [(10, 10), (0, 0), (10, -20)] # 移动的变化量
start_positions = [(1, -1), (0, 0)] # 起始位置
# 计算最终位置
final_positions = calculate_final_positions(n, m, movements, start_positions)
# 输出最终位置
for position in final_positions:
print(position) # 这会打印每个起始点的最终位置
C 语言也可以:
#include <stdio.h>
// 结构体用于存储点的坐标
typedef struct {
int x;
int y;
} Point;
// 函数用于计算最终位置
void calculate_final_positions(int n, int m, Point movements[], Point start_positions[]) {
for (int i = 0; i < m; ++i) {
Point final_position = start_positions[i];
for (int j = 0; j < n; ++j) {
final_position.x += movements[j].x;
final_position.y += movements[j].y;
}
// 打印最终位置
printf("%d %d\n", final_position.x, final_position.y);
}
}
int main() {
int n, m;
scanf("%d %d", &n, &m); // 读取移动次数和点的数量
Point movements[n]; // 存储所有移动的数组
for (int i = 0; i < n; ++i) {
scanf("%d %d", &movements[i].x, &movements[i].y); // 读取移动的变化量
}
Point start_positions[m]; // 存储所有起始位置的数组
for (int i = 0; i < m; ++i) {
scanf("%d %d", &start_positions[i].x, &start_positions[i].y); // 读取起始位置
}
// 计算并打印所有点的最终位置
calculate_final_positions(n, m, movements, start_positions);
return 0;
}
|