CCF-CSP real question "202309-1 Coordinate Transformation (Part 1)" Ideas + python, c++, java full score question solution

Students who want to check other real questions and solutions can go to: CCF-CSP real questions with solutions


Question number: 202309-1
Question name: Coordinate transformation (Part 1)
time limit: 1.0s
Memory limit: 512.0MB
Problem Description:

Problem Description

For coordinates (x,y) on the plane Cartesian coordinate system, small P defines a sequence of n operations T=(t1,t2,⋯,tn). Each operation ti (1≤i≤n) contains two parameters dxi and dyi, which means to translate the coordinate (x,y) to (x+dxi,y+dyi).

Now given m initial coordinates, try to calculate the final coordinates after performing n operations in T on each coordinate (xj, yj) (1≤j≤m).

Input format

Read data from standard input.

Enter a total of n+m+1 lines.

The first line of input contains two positive integers n and m separated by spaces, representing the number of operations and initial coordinates respectively.

The next n lines input n operations in sequence, where the i-th line (1≤i≤n) contains two space-separated integers dxi and dyi.

The next m lines input m coordinates in sequence, where the jth line (1≤j≤m) contains two integers xj and yj separated by spaces.

Output format

Output to standard output.

There are m lines of output, in which the jth line (1≤j≤m) contains two space-separated integers, representing the position of the initial coordinate (xj,yj) after n operations.

Sample input

3 2
10 10
0 0
10 -20
1 -1
0 0

Sample output

21 -11
20 -10

Sample description

The first coordinate (1,−1) becomes (21,−11) after three operations; the second coordinate (0,0) becomes (20,−10) after three operations.

Evaluation use case scale and conventions

All test data satisfies: n, m ≤ 100, all input data (x, y, dx, dy) are integers and the absolute value does not exceed 100000.

Source of real question: Coordinate transformation (Part 1)

 Interested students can code it like this and submit it for practice

python problem solution: 

n, m = map(int,input().split())
temp_x = temp_y = 0
for i in range(n):
    x1, y1 = map(int, input().split())
    temp_x += x1
    temp_y += y1
for i in range(m):
    x, y = map(int, input().split())
    x += temp_x
    y += temp_y
    print('{} {}'.format(x,y))

operation result:


C++ full score problem solution:

#include <bits/stdc++.h>
using namespace std;
int n, m;
int temp_x=0, temp_y=0;
int x, y;
int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> x >> y;
        temp_x += x;
        temp_y += y;
    }
    for (int i = 0; i < m; i++)
    {
        cin >> x >> y;
        x += temp_x;
    	y += temp_y;
    	cout << x <<" "<< y << "\n"; 
    }
    cout << endl;
    return 0;
}

 operation result:


 Java full score question solution:

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int temp_x = 0;
        int temp_y = 0;
        for( int i = 1; i <= n; i++ ) {
            int x = in.nextInt();
            int y = in.nextInt();
            temp_x += x;
            temp_y += y;
        }
        for( int i = 1; i <= m; i++ ) {
            int x = in.nextInt();
            int y = in.nextInt();
            x += temp_x;
            y += temp_y;
            System.out.println(x+" "+y);
        }
    }
}

  operation result:

 

Guess you like

Origin blog.csdn.net/weixin_53919192/article/details/133274096