3064 - I2P(I)2024_Yang_lab3 Scoreboard

Time

2024/10/01 22:00:00 2024/10/01 22:01:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
11146 Find the maximum/minimum values
14441 Trading Card Game

11146 - Find the maximum/minimum values   

Description

In this problem, you are asked to implement a program which can find the maximum element M and minimum element mof a two-dimensional array. You need to print the location difference and value difference of M and m. For example, if M is at iM-th row and jM-th column and of value rM, and m is at im-th row and jm-th column and of value rm, then the location difference and value difference of the two elements are (|iM - im| + |jM - jm|) and (|rM - rm|), respectively.

Note that in a given array, no two elements will have the same value.

 

HINT: You can use C library function:  int abs(int x) ,which returns the absolute value of int x.

Before using abs(), you may need to add the following code at first : #include <stdlib.h>

Input

The first line of the input contains two integer numbers R (2<=R<=10) and C (2<=C<=10).

Each of the next R lines contains C integers, specifying the elements of the two-dimensional array. All of the integers in the same line are separated by a space.

Output

The output contains two integers:  the location difference and the value difference of the maximum and minimum elements, separated by a space.

Note that you do not need to print ‘\n’ at the end of line.

Sample Input  Download

Sample Output  Download

Tags




Discuss




14441 - Trading Card Game   

Description

There are N players in a trading card game(集換式卡牌遊戲), each player has a card binder that holds a certain number of cards. Player i 's binder has Mi card slots, and initially, the j-th slot of player 's binder holds a unique card numbered Ai, j.

Since this is a trading card game, "card trading" is naturally an essential aspect. You are given T trades between the players. Each trade involves 4 numbers: x1, y1i , x2i , and y2i . This means player x1i trades the card in slot y1i of their binder with the card in slot y2i of player x2i ’s binder.

The trades occur in the order they are given. That is, the i-th trade happens before the (i +1)-th trade.

After all the trades are completed, you need to answer Q queries. Each query consists of a number, numi. For each query, you need to report two numbers, pi and ci, representing that the card numbered numi is in slot ci of player pi's binder after all the trades have taken place.

Input

The first line of input contains an integer N, representing the number of players.

The second line contains N integers M1, M2, ..., MN, where Mi represents the capacity (number of cards) of the i-th player's card binder.

The next N lines, where the i-th line contains Mi integers, represent the initial card numbers in the binder of the i-th player: Ai, 1, Ai, 2, ..., Ai, Mi.

After that, there is an integer T representing the number of card trades.

The next T lines each contain 4 integers x1i, y1i, x2i, y2i, indicating that the card in the y1-th slot of the x1-th player’s binder is traded with the card in the y2-th slot of the x2-th player’s binder.

The final line contains an integer Q, representing the number of queries.

The next line contains Q integers num1, num2, ..., num, separated by spaces, representing queries asking for the locations of the cards numbered numi.

 

Constraints

  • 1 ≤ ≤ 1000
  • 1 ≤ Q ≤ 105
  • 0 ≤ T ≤ 106
  • 1 ≤ Mi ≤ 105 , Σ Mi ≤ 106
  • 1 ≤ Ai, j ≤ Σ Mi 
  • for all ( i, j ) ≠ ( k, l ) ,  Ai, j ≠ Ak, l 
  • 1 ≤ x1,x2 ≤ N
  • for all α = x1, 1 ≤ y1i ≤ Mα
  • for all α = x2, 1 ≤ y2i ≤ Mα
  • 1 ≤ numi ≤ Σ Mi 

 

Subtasks

  • Testcases 1: N = 1 ; T = 0
  • Testcases 2~4: N = 1 ; T,Q ≤ 100 
  • Testcases 5~6: N = 1
  • Testcases 7: N = 2 ; Q ≤ 100
  • Testcases 8: N,Q ≤ 100
  • Testcases 9~10: No additional restrictions.

Output

For each query, output two integers, pi and ci representing that the card numbered numi is in the ci-th slot of the pi-th player's binder after all the trades have taken place.

Please remember to print "\n" at the end of each query.

When outputting pi and ci, ensure there is a space between them, and make sure there is no space after ci. Otherwise, you may get a Presentation Error.

Sample Input  Download

Sample Output  Download

Tags




Discuss