0% found this document useful (0 votes)
4 views

as3_statement

The document outlines the requirements for a programming assignment, including coding guidelines in Java, Python, C, or C++, and the need for a report explaining the problem-solving process. It provides an example problem, submission instructions, and details on penalties for late submissions. Additionally, it describes three specific problems related to a football game, watermelon volume, and tree distance calculations, each with input/output specifications and constraints.

Uploaded by

3154482093
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

as3_statement

The document outlines the requirements for a programming assignment, including coding guidelines in Java, Python, C, or C++, and the need for a report explaining the problem-solving process. It provides an example problem, submission instructions, and details on penalties for late submissions. Additionally, it describes three specific problems related to a football game, watermelon volume, and tree distance calculations, each with input/output specifications and constraints.

Uploaded by

3154482093
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

A.

Requirements
Code (90%)
You can write your code in Java, Python, C, or C++. The time limit may vary among different
languages, depending on the performance of the language. Your code must be a complete excutable
program instead of only a function. We guarantee test data strictly compliance with the requirements
in the description, and you do not need to deal with cases where the input data is invalid.
Libraries in this assignment:
• For C/C++, you can only include standard library.
• For Java, you can only import java.util.*
• For Python, you can only import standard library. In other words, you cannot import libraries
such as numpy.

Report (10%)
You also need to write a report in pdf type to explain the following:
• What are the possible solutions for the problem?
• How do you solve this problem?
• Why is your solution better than others?
Please note that the maximum number of pages allowed for your report is 5 pages.
Remember that the report is to illustrate your thinking process. Keep in mind that your report is
supposed to show your ideas and thinking process. We expect clear and precise textual descriptions
in your report, and we do not recommend that you over-format your report.

B. Example Problem: A + B Problem


Description
Given 2 integers A and B, compute and print A + B

Input
Two integers in one line: A, and B

Output
One integer: A + B

Sample Input 1 Sample Output 1


1 2 3

Problem Scale & Subtasks


For 100% of the test cases, 0 ≤ A, B ≤ 106

1
Solutions
Java
import java . util .*;

public class Example {


public static void main ( String [] args ) {
int a , b ;
Scanner scanner = new Scanner ( System . in );
a = scanner . nextInt ();
b = scanner . nextInt ();
scanner . close ();
System . out . println ( a + b );
}
}

Python
AB = input (). split ()
A , B = int ( AB [0]) , int ( AB [1])
print ( A + B )

C
# include < stdio .h >

int main ( int argc , char * argv [])


{
int A , B ;
scanf ( " % d % d " , &A , & B );
printf ( " % d \ n " , A + B );
return 0;
}

C++
# include < iostream >

int main ( int argc , char * argv [])


{
int A , B ;
std :: cin > > A >> B ;
std :: cout < < A + B << std :: endl ;
return 0;
}

C. Submission
After finishing this assignment, you are required to submit your code to the Online Judge System
(OJ), and upload your .zip package of your code files and report to BlackBoard.

C.1 Online Judge


Once you have completed one problem, you can submit your code on the page on the Online Judge
platform (oj.cuhk.edu.cn, campus only) to gain marks for the code part. You can submit your
solution of one problem for no more than 80 times.
After you have submitted your program, OJ will test your program on all test cases and give you a
grade. The grade of your latest submission will be regarded as the final grade of the corresponding
problem. Each problem is tested on multiple test cases of different difficulty. You will get a part of
the score even if your algorithm is not the best.

2
Note: The program running time may vary on different machines. Please refer to the result of
the online judge system. OJ will show the time and memory limits for different languages on the
corresponding problem page.
If you have other questions about the online judge system, please refer to OJ wiki (campus network
only). If this cannot help you, feel free to contact us.

C.2 BlackBoard
You are required to upload your source codes and report to the BlackBoard platform. You need
to name your files according to the following rules and compress them into A1_<Student ID>.zip :
A1_ < Student ID >. zip
| - - A1_P1_ < Student ID >. java / py / c / cpp
| - - A1_P2_ < Student ID >. java / py / c / cpp
| - - A1_Report_ < Student ID >. pdf

For Java users, you don’t need to consider the consistency of class name and file name.
For example, suppose your ID is 123456789, and your problem 1 is written in Python, problem 2 is
written in Java then the following contents should be included in your submitted A1_123456789.zip:
A1_123456789 . zip
| - - A1 _P 1_ 1 23 45 67 8 9 . py
| - - A1 _P 2_ 1 23 45 67 8 9 . java
| - - A 1 _ R e p o r t _ 1 2 3 4 5 6 7 8 9 . pdf

C.3 Late Submissions


Submissions after Mar 27, at 23:59 PM (UTC+8) would be considered as LATE. A late submission
contest will open after deadline.
Submisson time = max{latest submisson time for every problem, BlackBoard submisson time}
There will be penalties for late submission:
• 0–24 hours after deadline: final score = your score×0.8
• 24–72 hours after deadline: final score = your score×0.5
• 72+ hours after deadline: final score = your score×0

FAQs
Q: I cannot access to Online Judge.
A: First, please ensure that you are using the campus network. If you are not on campus, please use
the university VPN. Second, please delete cookies and refresh browser or use other browser. If you
still cannot access to Online Judge, try to visit it via the IP address 10.26.200.13.
Q: My program passes samples on my computer, but not get AC on OJ.
A: Refer to OJ Wiki Q&A

Authors
If you have questions for the problems below, please contact:
• Problem 1. The 2023 Programming Contest of CUHK-Shenzhen (official)
• Problem 2. The 2023 Programming Contest of CUHK-Shenzhen (official)
• Problem 3. Yige Jiang: [email protected]

3
CSC3100 Data Structures Spring 2024

Programming Assignment 3

Due: Apr 16 2024 23:59:00

Assignment Link: http://oj.cuhk.edu.cn/contest/csc310024spa3


Access code: flute
Question 1, question 2, and question 3 weigh 25%, 25%, and 40% of the total grade, respectively.
Please note that you are not recommended to use AI tools such as chatGPT to complete
your assignment for potential plagiarism issue.

1 PigCup Final (25% of this assignment)


1.1 Description
Football is a favorable sport in Pigeland, and PigCup is considered the most prestigious football game
in the country.
The final of the 2023 PigCup was played between Team A and Team B. Piggy, a rising star in the
sport, was selected to represent Team A in the final. Sadly, Piggy fell ill and overslept, causing him
to miss the game. Nevertheless, as the team captain, Piggy is eager to learn about the outcome of the
2023 PigCup final.
In PigCup, the team with a higher number of scores will win the game; the game will result in a tie
if the two teams get the same number of scores. The events in the 2023 PigCup final are represented
by a string S consisting of the letters ‘A’ or ‘B’, where each ‘A’ indicates a score for Team A and each
‘B’ indicates a score for Team B. In particular, in the case where no team scores, i.e. the final result
is 0:0, S will only contain a single letter ‘O’.
Now, Piggy gives you the string S. Your task is to help Piggy determine the winning team or whether
the game results in a tie.

1.2 Input
The inputs consist of a single line that contains a string S of at most 20 letters. Each letter in S is
either of ‘A’, ‘B’ or ‘O’, where ‘A’ means Team A scores, ‘B’ means Team B scores, while ‘O’ means
no team scores in the 2023 PigCup final.

1.3 Output
Output the scores of Team A and Team B on the first two lines, respectively, with the format “A:X”
and “B:Y”, where X is the score of Team A and Y is the score of Team B.
On the third line, output the result of the game. If Team A wins, output “A wins!”. If Team B wins,
output “B wins!”. If the game results in a tie, output “Draw!”. The detailed output format can be
found in the example.

4
Figure 1: Enter Caption

Sample Input 1 Sample Output 1


A: 2
BAA B: 1
A wins !

You can find more samples in the attached file on BB.

1.4 Problem Scale & Subtasks


There are 10 testcases in total, the length of the given string is at most 20 letters.

2 Watermelon (25% of this assignment)


2.1 Description
In Pigeland, watermelon is the most renowned fruit among pigs. There is an ancient saying: the larger
the watermelon, the larger the watermelon rind.
Small Piggy is Piggy’s sister, a critically-minded girl. She thinks this idiom is incorrect in some special
situations. In order to support her, you want to find such an example.
You found two round watermelons. The smaller one has a radius r1 , you cut it apart and figured out
that its rind has thickness d. The larger one has a radius r2 . Before cutting it open, you want to know
the maximum thickness of the second rind to let the volume of the second watermelon rind be smaller
than the volume of the first watermelon rind.
Note that the watermelons are perfectly ball-shaped. A watermelon has two parts — watermelon pulp
and watermelon rind. The watermelon pulp is also ball-shaped and it is concentric with the watermelon
itself.

2.2 Input
Each test contains multiple test cases. The first line contains a single integer T (1 ≤ T ≤ 30 000) —
the number of test cases. A description of the test cases follows.
The only line for each test case contains three integers in one line, r1 , r2 , d (1 ≤ d < r1 < r2 ≤ 1 000).

5
2.3 Output
For each testcase, output one real number in a line, representing the maximum thickness of the second
watermelon rind.
Your answer will be considered correct if its absolute or relative error does not exceed 10−4 .

Sample Input 1 Sample Output 1


2 0.2855823834
2 3 1 0.4423278138
5 7 1

You can find more samples in the attached file on BB.

2.4 Problem Scale & Subtasks


There are 10 testcases in total.
For the all given testcases, 1 ≤ T ≤ 3 × 104 , 1 ≤ d < r1 < r2 ≤ 1000.

3 Tree Problem (40% of this assignment)


3.1 Description
Given an unrooted tree with n nodes, where each node is either black or white, and the tree has edge
weights.
For positive integers u, v ∈ [1, n], define dis(u, v) as the distance between nodes u and v on the tree.
Define:  
n
X
ansi =  dis(i, j) %mod
j=1,j̸=i,j∈black nodes

Output the array {ansi }, i ∈ [1, n], where mod = 109 + 7.

3.2 Input
The first line contains an integer n.
The second line contains n numbers, where the i-th number represents the color of node i (1 for black,
0 for white).
The following n − 1 lines, each line contains three integers u, v, w, representing an edge connecting
node u and node v with a distance of w. Note that n, u, v, w > 0.

3.3 Output
Output n lines, the i-th line represents ansi .

Sample Input 1 Sample Output 1


5 10
1 0 1 1 1 10
1 2 3 14
1 3 2 12
2 4 1 12
2 5 1

6
You can find more samples in the attached file on BB.

3.4 Problem Scale


1 ≤ u, v ≤ n, 1 ≤ w ≤ 1000

Test Data Scale. Constraints


30% data 1 ≤ n ≤ 100
70% data 1 ≤ n ≤ 2000
100 % data 1 ≤ n ≤ 100000

3.5 Hint
For Python users, if there occurs a RecusrionError, see here.

You might also like