Problem Title : Magical Cave
Lili, a great magician, has a mission to enter a cave to get treasure inside. The cave only has 1 path without branches. But the cave is not safe because there are some traps inside that can reduce Lili’s life points. But in addition to traps, the cave also has potions that can increase Lili’s life points. Before entering the cave, Lili casts magic that can reveal all the traps and potions inside the cave. But before entering the cave, Lili must prepare her life points first because in the cave because Lili cannot use her magic to add life points or destroy the traps. What is the minimum life point that Lili must prepare so that her life point is always positive during the trip inside the cave.
Note: if Lili's point drops to 0 or negative before entering and during the trip inside the cave, then Lili is declared dead.
Format Input
There are T test cases. Each testcase contains an integer N which represents the length of the cave. On the next line there are N numbers represents the value of trap and potion. Traps are marked with numbers that are negative and potions are marked with numbers that are positive.
Format Output
Output T line with format “Case #X: ”, where X represents the testcase number and Y represents the initial life points that Lili has to prepare.
Constraints
Sample Input & Output (standard input & output)
2
5
1 2 -3 4 -5
Case #1: 2
5
-1 -1 -1 -2 9
Case #2: 6
Explanation
In case 1, the minimum life points that Lili must prepare is 2.
With a simulation like the following.
At position 1, Lili’s life point increased by 1 to 3.
At position 2, Lili’s life point increased by 2 to 5.
At position 3, Lili’s life point is reduced by 3 to 2.
At position 4, Lili’s life point increased to 4 to 6.
At position 5, Lili’s life point is reduced by 5 to 1.
In each position Lili’s life points are Positive so the
answer is Valid. if the initial life
prepared by Lili is 1, then Lili will die in fifth position with a
life point of 0.
In: Computer Science
Java question: Write a method printCombinationR(int[] array, int r) that generates and prints all possible combinations of r elements in array of size n,. For example, if input array is {1, 2, 3, 4} and r is 2, then output should be {1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4} and {3, 4}.
I kind of know how to write this with DFS with four or five formal parameters, however I don't know how to solve it after the formal parameters are restricted by only using (int[] array, int r).
In: Computer Science
Write the script in python to carry out the z- normalization on "Salary", if the Mean is 79.6 and standard deviation is 14.4152. Assume the data is read from a csv file titled "Comp_sal_2014.csv".
In: Computer Science
In: Computer Science
Discuss the types of distribution transparency as they may benefit to various business contexts. Provide illustrative examples.
Database Management Question
In: Computer Science
What are the major drawbacks of static allocation? How does a hybrid allocation scheme consisting of static allocation, stack-based allocation, and heap based allocation solve the problem
In: Computer Science
Java 2D Drawing Application.
The application will contain the following elements:
a) an Undo button to undo the last shape drawn.
b) a Clear button to clear all shapes from the drawing.
c) a combo box for selecting the shape to draw, a line, oval, or
rectangle.
d) a checkbox which specifies if the shape should be filled or
unfilled.
e) a checkbox to specify whether to paint using a gradient.
f) two JButtons that each show a JColorChooser dialog to allow the
user to choose the first and second color in the gradient.
g) a text field for entering the Stroke width.
h) a text field for entering the Stroke dash length.
I) a checkbox for specifying whether to draw a dashed or solid
line.
j) a JPanel on which the shapes are drawn.
k) a status bar JLabel at the bottom of the frame that displays the
current location of the mouse on the draw panel.
If the user selects to draw with a gradient, set the Paint on the
shape to be a gradient of the two colors chosen by the user. If the
user does not chose to draw with a gradient, then Paint with a
solid color of the 1st Color. The following code can create a
gradient paint object:
Paint paint = new GradientPaint(0, 0, color1, 50, 50, color2,
true);
To set the stroke for a line to be drawn, you can use the following code:
if (dashCheckBox.isSelected())
{
stroke = new BasicStroke(lineWidth, BasicStroke.CAP_ROUND,
BasicStroke.JOIN_ROUND, 10, dashLength, 0);
} else
{
stroke = new BasicStroke(lineWidth, BasicStroke.CAP_ROUND,
BasicStroke.JOIN_ROUND);
}
Where the first stroke line creates a dashed line and dashLength is a one element float array with the dash length in the first element. The second stroke line creates an undashed line with the line width specified from the GUI.
Note: When dragging the mouse to create a new shape, the shape should be drawn as the mouse is dragged.
A template project has been provided for you in Canvas in Java2DDrawingApplicationTemplate.zip. This project contains a MyShapes hierarchy that is a complete shape hierarchy for drawing a line, rectangle or oval. You must use this MyShapes hierarchy. A template for the Drawing Application Frame is also provided along with a template for the DrawPanel inner class. You do not need to use these templates if you so choose.
In the paintComponent(Graphics g) method of the DrawPanel, to loop through and draw each shape created by the user, you will loop through an ArrayList of MyShapes, that you built, and call the draw(Graphics2D g2d) method for each shape. The draw method is already implemented in the MyShapes hierarchy.
Note: You do not need to create an event handler for each component in the top two lines of the frame. You only need to create event handlers for the buttons. You can get the values out of all the other components in the top two lines, when the user presses the mouse button on the DrawPanel. At that time, you have all the information you need to create a new Myshapes object.
Note: Do not use the NetBeans GUI generator for this assignment.
-------------------------------------------------------------------- PLEASE USE THE FOLLOWING FILES!!! -----------------------------------------------------------------------
https://drive.google.com/file/d/1wiRjRNrunGPYMeWD2qM7Zgj6H0jg_SAa/view?usp=sharing
Thank you!
In: Computer Science
The verticies of ABC are A(2,4), B (7,6) and C(5,2) give the correct composition of the matricies for the image of ABC after the given composition of the transformations in the order listed(show what it would be for each vertex)
First Translation: (x, y) -> (x-2,y-3)
Second Rotation: 75 degrees about the pivot popoint (1,3)
In: Computer Science
In: Computer Science
i need to find complexity and cost and runtime for each line of the following c++ code :
// A C++ program for Dijkstra's single source shortest path
algorithm.
// The program is for adjacency matrix representation of the
graph
#include <limits.h>
#include <stdio.h>
// Number of vertices in the graph
#define V 9
// A utility function to find the vertex with minimum distance
value, from
// the set of vertices not yet included in shortest path tree
int minDistance(int dist[], bool sptSet[])
{
// Initialize min value
int min = INT_MAX, min_index;
for (int v = 0; v < V; v++)
if (sptSet[v] == false &&
dist[v] <= min)
min = dist[v],
min_index = v;
return min_index;
}
// A utility function to print the constructed distance
array
void printSolution(int dist[])
{
printf("Vertex \t\t Distance from Source\n");
for (int i = 0; i < V; i++)
printf("%d \t\t %d\n", i,
dist[i]);
}
// Function that implements Dijkstra's single source shortest
path algorithm
// for a graph represented using adjacency matrix
representation
void dijkstra(int graph[V][V], int src)
{
int dist[V]; // The output array. dist[i] will hold
the shortest
// distance from src to i
bool sptSet[V]; // sptSet[i] will be true if vertex
i is included in shortest
// path tree or shortest distance from src to i is
finalized
// Initialize all distances as INFINITE and
stpSet[] as false
for (int i = 0; i < V; i++)
dist[i] = INT_MAX, sptSet[i] =
false;
// Distance of source vertex from itself is always
0
dist[src] = 0;
// Find shortest path for all vertices
for (int count = 0; count < V - 1; count++) {
// Pick the minimum distance vertex
from the set of vertices not
// yet processed. u is always equal
to src in the first iteration.
int u = minDistance(dist,
sptSet);
// Mark the picked vertex as
processed
sptSet[u] = true;
// Update dist value of the
adjacent vertices of the picked vertex.
for (int v = 0; v < V; v++)
// Update
dist[v] only if is not in sptSet, there is an edge from
// u to v, and
total weight of path from src to v through u is
// smaller than
current value of dist[v]
if (!sptSet[v]
&& graph[u][v] && dist[u] != INT_MAX
&& dist[u] + graph[u][v] <
dist[v])
dist[v] = dist[u] + graph[u][v];
}
// print the constructed distance array
printSolution(dist);
}
In: Computer Science
URGENT JAVA
Develop a Java computer program to simulate access control to a system network. The username and password authentication mechanism is used as an access control mechanism in this project. The program needs to authenticate the user with their username and hashed password stored in Access Manager User (AMU) file. To create an Access Manager User file, you need to develop a java program that takes username and password as input and then generates a file containing the username, hashed password, and plaintext password. In real world, the plaintext are not saved in the AMU file. However, you need the username and corresponding plaintext password for testing of your main program. The structure of the AMU file is shown in the appendix. Note that this should be done as a separate program. The main program operates in the following manner. It first prompts the user to enter username and password. After the user enters both username and password, it hashes the password and search the AMU file to verify both the user name and password. If the program verifies the username and password, it returns the message “Access Granted.” If the programcould not verify the username, it returns the message “Access Denied. You are not a registered user.” If the program verifies the username but not the password, it prompts the user to enter the password again. If the user enter the password three times incorrectly, the system locks the user account and gives this message. “You exceeded entering the allowablenumber of incorrect password. Your account is locked. Contact system administrator to unlock your account”
In: Computer Science
What are the key activities performed in the implementation phase and how are they connected in project management?
In: Computer Science
IN JAVA
Step 1 Develop the following interface: Interface Name: ImprovedStackInterface Access Modifier: public Methods Name: push Access modifier: public Parameters: item (data type T, parameterized type) Return type: void Throws: StackFullException Name: push Access modifier: public Parameters: item1 (data type T, parameterized type), item2 (data type T, parameterized type) Return type: void Throws: StackFullException Name: pop Access modifier: public Parameters: none Return type: void Throws: StackEmptyException Name: doublePop Access modifier: public Parameters: none Return type: void Throws: StackEmptyException Name: top Access modifier: public Parameters: none Return type: T (parameterized type) Throws: StackEmptyException Step 2 Develop the following class: Class Name: StackFullException Access Modifier: public Extends: Exception Constructors Name: StackFullException Access modifier: public Parameters: none (default constructor) Task: makes a call to the default constructor of its superclass Name: StackFullException Access modifier: public Parameters: message (datatype String) Task: makes a call to the constructor of its superclass by passing the parameter message to it Step 3 Develop the following class: Class Name: StackEmptyException Access Modifier: public Extends: Exception Constructors Name: StackEmptyException Access modifier: public Parameters: none (default constructor) Task: makes a call to the default constructor of its superclass Name: StackEmptyException Access modifier: public Parameters: message (datatype String) Task: makes a call to the constructor of its superclass by passing the parameter message to it Step 4 Develop the following class: Class Name: ImprovedArrayBasedStack Access Modifier: public Implements: ImprovedStackInterface Instance variables Name: top Access modifier: private Data type: int Name: stack Access modifier: private Data type: T[] (an array of parameterized type) Constructors Name: ImprovedArrayBasedStack Access modifier: public Parameters: none (default constructor) Task: sets the value of top to -1 sets the stack to refer to an array of Objects with 100 elements which are type cast to T[] Name: ImprovedArrayBasedStack Access modifier: public Parameters: size (data type int) Task: sets the value of top to -1 sets the stack to refer to an array of Objects with the number of elements equal to the size parameter which are type cast to T[] Methods Name: push Access modifier: public Parameters: item (data type T, parameterized type) Return type: void Throws: StackFullException Task: if the value of top is less than the length of the stack minus 1 then increase the value of top by 1 and place the item at the top of the stack, otherwise throw a StackFullException with the message "Not enough room for one item" Name: push Access modifier: public Parameters: item1 (data type T, parameterized type), item2 (data type T, parameterized type) Return type: void Throws: StackFullException Task: if the value of top is less than the length of the stack minus 2, then increase the value of top by 1 and place item1 at the top of the stack, then increase the value of top by 1 and place item2 at the top of the stack, otherwise throw a StackFullException with the message "Not enough room for two items" Name: pop Access modifier: public Parameters: none Return type: void Throws: StackEmptyException Task: if the value of top is greater than -1 then remove the item at the top of the stack by replacing it with null and decrease the value of top by 1, otherwise throw a StackEmptyException with the message "No item to remove" Name: doublePop Access modifier: public Parameters: none Return type: void Throws: StackEmptyException Task: if the value of top is greater than 0, then remove the item at the top of the stack by replacing it with null and decrease the value of top by 1, then remove the item at the top of the stack by replacing it with null and decrease the value of top by 1, otherwise throw a StackEmptyException with the message "There are less than two items in the stack" Name: top Access modifier: public Parameters: none Return type: T (parameterized type) Throws: StackEmptyException Task: if the value of top is greater than -1 then return the item at the top of the stack, otherwise throw a StackEmptyException with the message "Top attempted on an empty stack" Step 5 Develop a class with only a main method in it: import java.util.Scanner; public class ImprovedStackDemo { public static void main(String[] args) { /* Inside of this main method do the following: Create an object of the Scanner class that takes input from System.in and refer to this object as keyboard Create a reference to a ImprovedStackInterface called myImprovedStack and have it refer to a new object of the ImprovedArrayBasedStack type passing the value of 6 as an argument to the constructor Open a do/while loop Prompt the user to pick one of the following options: Press 1 to push one item onto the stack Press 2 to push two items onto the stack Press 3 to pop the top of stack Press 4 to pop the top of the stack twice Press 5 to look at the top of the stack Press 6 to end the program Save the user’s input into the option variable if the user picks option 1, prompt the user for what they would like to push onto the stack then save that in a variable called item Open a try block and inside that block call the push method by passing item as a parameter and then close the try block Open a catch block catching StackFullException e and inside this catch block print out the value of message stored in the exception else if the user picks option 2, prompt the user for what they would like to push onto the stack then save that in a variable called item1 Prompt the user for the second item that they would like to push onto the stack and save that in a variable called item2 Open a try block and inside that block call the push method by passing item1 and item 2 as parameters and then close the try block Open a catch block catching StackFullException e and inside this catch block print out the value of the message stored in the exception else if the user picks option 3, Open a try block and call the pop method and close the try block Open a catch block catching StackEmptyException e and inside this catch block print out the value of the message stored in the exception else if the user picks option 4, Open a try block and call the doublePop method and close the try block Open a catch block catching StackEmptyException e and inside this catch block print out the value of the message stored in the exception else if the user picks option 5, Open a try block and print the value returned by the top method and close the try block Open a catch block catching StackEmptyException e and inside this catch block print out the value of the message stored in the exception else if the user picks option 6, display Goodbye. else if the user picks any other option, display Error! close the do/while loop and make it so that it continues to run as long as the user does not pick option 6 */ } }
In: Computer Science
Describe a project, or process, where quality assurance may be one of the most costly activities? please explain
In: Computer Science