| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10851 | Equivalent relation (Find maximum) |
|
| 11728 | Distance on 2D plane |
|
| 11732 | I2P(I)_Mid2Bonus_EECS |
|
Description
There are N integer pointers, indexed from 0 to N-1 (N<100). Each pointer initially points to an integer of value 0.
There are three kinds of instructions.
1. “S n k” : n is the index of the pointer, and k is an integer value; this operation is to assign the value k to the integer pointed by pointer n; after this operation, the integer pointed by pointer n will have a value k.
2. “M n k”: n is the index of the pointer, and k is an integer value; this operation is to multiply the integer pointed by pointer n by k times; after this operaiton, the integer pointed by pointer n will be k times larger.
3. “P n m”: n and m are the indexes of two pointers; this operation is to make pointer n point to the same integer as pointer m; after this operation, m and n will point at the same address.
After some manipulation following the given instructions, we want to find out the maximum of what pointer array points to in some specific range, which is also given by the input.
Note that
1. This problem involves three files.
- function.h: Function definition of execInst, findMax.
- function.c: Function describe of execInst, findMax.
- main.c: A driver program to test your implementation.
You will be provided with main.c and function.h, and asked to implement function.c.
2. For OJ submission:
Step 1. Submit only your function.c into the submission block. (Please choose c compiler)
Step 2. Check the results and debug your program if necessary.
Hints:
main.c
#include <stdio.h>
#include "function.h"
#define SIZE 100
int main() {
int *ptrArr[SIZE];
int dataArr[SIZE] = {0};
char inst;
int dataNum, instNum;
int param1, param2;
int start, end;
int i;
/* input */
scanf("%d %d", &dataNum, &instNum);
/* initialize the ptrArr */
for (i = 0; i < dataNum; i++)
ptrArr[i] = &dataArr[i];
for (i = 0; i < instNum; i++) {
scanf(" %c %d %d", &inst, ¶m1, ¶m2);
execInst(ptrArr, inst, param1, param2);
}
scanf("%d %d", &start, &end);
/* output */
for (i = 0; i < dataNum - 1; i++) {
printf("%d ", dataArr[i]);
}
printf("%d\n", dataArr[i]);
for (i = 0; i < dataNum - 1; i++) {
printf("%d ", *ptrArr[i]);
}
printf("%d\n", *ptrArr[i]);
printf("%d\n", findMax(ptrArr , start, end));
return 0;
}
function.h
#ifndef FUNCTION_H
#define FUNCTION_H
void execInst(int *ptrArr[], char inst, int param1, int param2);
int findMax(int *ptrArr[], int start, int end);
#endif
function.c
#include "function.h"
void execInst(int *ptrArr[], char inst, int param1, int param2){
if(inst=='S'){
/--your code--/
}
else if(inst=='M'){
/--your code--/
}
else if(inst=='P'){
/--your code--/
}
}
int findMax(int *ptrArr[], int start, int end){
/--your code--/
return max;
}
Input
The first line contains two positive X and Y. X indicates the size of data. Y indicates that there are Y instructions needed to be done.
The next Y lines contain the instructions.
The last line contain two integers, start and end respectively.
Output
First line: All the values that dataArr[0] to dataArr[N-1] stored in order. Each value is seperated by a blank ' '.
Second line: All the values that ptrArr[0] to ptrArr[N-1] point to in order. Each value is seperated by a blank ' '.
Final line: The max value that ptrArr[start] to ptrArr[end] point to.
Sample Input Download
Sample Output Download
Partial Judge Code
10851.cPartial Judge Header
10851.hTags
Discuss
Description
TA knows that in Monday lecture, HT taught everyone the concept of structure.
Moreover, the hackthon will be held on Saturday, and you students will use lots of APIs, containing many usages of structure.
Therefore, TA wants to ensure that you have enough basic knowledge of structure through this problem.
In this problem, TA forces you to use structure to record imformation and use afterward.
You will be given several points' locations on 2D plane(x, y), and you should compute the Euclidean distance of specific two points.

(Hint: you can use sqrt() to calculate the square root)

You should implement funcion.c below and submit it. (Due to Partial judge)
#include <stdio.h>
#include <math.h>
#include "function.h"
Point * ones_vec_1(int length)
{
/// Please implement
/// 1. Malloc memory for point array
/// 2. Read values into point array
/// 3. Return the address of the first element in the array
}
float compute_distance(Point* a, int first_id, int second_id)
{
float ans;
Point first_p, second_p;
/// Please implement
/// 1. Get two point from function argument
/// 2. Compute 2D distance and return ans
return ans;
}
You should see .c and .h file below to know how the function and the whole program works.
Input
Input may have several lines.
The first line contains an integer M, indicating how many points' locations you should read.
(Notice that the first point is indexed 0, and the second point is indexed 1, and so on...)
And the next M lines , each line has two integers, indicating point's location x and y.
The next line contains an integer N, indicating the number of the pairs of chosen two points.
And the next N lines, each line contains two integers, which are two indices representing two specific points needed to be calculated for Euclidean distance.
Output
Ouput has N lines.
Each line contains a floating number, indicating the Euclidan distance of two specific points.
Sample Input Download
Sample Output Download
Partial Judge Code
11728.cPartial Judge Header
11728.hTags
Discuss
Description
Source: I2P(I)2017_Chen_Midterm2_Practice pD - Fire
Writer: jjjjj19980806 Description: pclightyear Photo Credit: eccioa Difficulty: ★★★☆☆

Fi - Fi - Fi - Fire!!!!!!!!!!!!
eccioa loves playing minecraft, but he is on fire now!
He looks at the mini map, and he wants to found out if there is any water nearby to put out the fire on him. Unfortunately, there is also some lava nearby, and he can't pass through it (he forgot to bring the potion of fire resistance). If he can't reach any of the water on the map, he will be burned to death miserably.
eccioa now gives you the mini map sized m ✕ n consists of four symbols:
'e' stands for the current position of eccioa.
'.' stands for the regular road he can pass through.
'^' stands for lava he cannot pass through.
'~' stands for water. (There may be multiple of them)
Can you tell him whether he can stay alive or not?
Input
The first line contains two integer m, n, representing the size of the map eccioa gives to you.
The next m lines contain n characters, either 'e', '.', '^', '~', representing the status of position aij.
It is guaranteed that :
- 1 ≤ m, n ≤ 1000
Output
If eccioa can stay alive, please print "Alive!", and print the distance of the shortest path.
Otherwise please print "Dead!".