# | Problem | Pass Rate (passed user / total user) |
---|---|---|
11443 | 3DShape |
|
13879 | Tree-Graph Inheritance |
|
Description
Warning: You are not allowed to use malloc and free
Giving a bass-class Shape3D and 4 derived class : Sphere (球體), Cone (圓錐), Cuboid (長方體), Cube (立方體)
You need to calculate the volume of each shape.
PS:
V of Sphere: V = 4/3 π r3
V of Cone: V = 1/3 π r2 h
note : Remember to do some basic check, if the input is illegal (e.g. length < 0, pi < 0 .....) then the volume should be 0.
You don't need to consider the scenario like Cuboid -1 -2 3, volume would be 0 instead of 6.
Hint1: Be careful the type of volume is double. 4/3=1 (int), so it should be 4.0/3.0
Hint2: You only need to implement the constructors.
Hint3: Note that Cube inherited Cuboid not Shape3D.
Input
There are only 4 shapes in this problem :
- Sphere, following by its radius and pi. (e.g. Sphere 30 3.14)
- Cone, following by its radius of bottom plane, height and pi. (e.g. Cone 3 100 3.14)
- Cuboid, following by its length, width and height. (e.g. Cuboid 2 3 7)
- Cube, following by its length. (e.g. Cube 2)
Output
Ouput the total volume of all the shapes.
Sample Input Download
Sample Output Download
Partial Judge Code
11443.cppPartial Judge Header
11443.hDiscuss
Description
In Object-Oriented Programming (OOP), the inheritance among classes represent ``is-a'' relationships for abstractions. Graphs and trees are both fundamental for computer science. In fact, a tree is a special case of a graph that is connected as well as acyclic.
In fact, we often implement trees and graphs by similar means in practice. For instance, we tend to store trees and graphs by adjacent matrice or lists. Moreover, we traverse trees and graphs in alike ways.
For simplicity, we only consider basic operations on trees and graphs. You need implement BFS traversal for a graph starting from a given source and returning the distance to all other vertices so that trees could inherit that method. Furthermore, you should find the diameter (the longest distance in a tree that we've encountered several times but solved by DFS then) by BFS traversal.
Input
Please see the instructions in the header. BFS traversal would be called with the source. As for diameter, there's no parameter.
It's guaranteed that the graph is connected and simple, and that the number of vertices of a tree is less than 100000.
Output
For BFS traversal, you should return a vector of n integers indicating the minimum distance from source.
As for the diameter, you should return an integer.