|
My wife still has an old phone that she keeps powered up just for that.
|
|
|
|
|
can't able to fine exact code. its confusing
|
|
|
|
|
Part of the art of becoming a programmer is knowing how to search. Paste your search link in as a reply so I can see how you searched.
This space for rent
|
|
|
|
|
|
The search terms I used. Google[^]
This space for rent
|
|
|
|
|
|
thanks but i dont know how to run it. its not giving an error but dont know how to compile it. not giving any output
|
|
|
|
|
The links I found are just to point you to the information that may help you. It is up to you to work out how to use it and, if necessary, find out why it does not work.
|
|
|
|
|
We are not a free search service!
We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.
As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
how rude ur ans
|
|
|
|
|
I don't think it was rude. He was trying to give you some genuine advice that will stand you in good stead in the years to come... as have the others that are suggesting that you actually need to put some of your own effort into this exercise.
|
|
|
|
|
In some cities, the sewage system does not work properly and every time it rains, water accumulates on the streets and in between buildings, blocking traffic and causing distress.
You have an N number of buildings and an array with the height of every building.
You want to find out what is the maximum volume of water that would hypothetically accumulate after heavy rain, in between 2 buildings.
Input: N > 0 on the first line, array of N integer elements on the second line.
Output: integer positive X units of water.
Example: The following sequence of heights will generate the structure below:
Sequence: 1 2 1 5 2 4 1 0 1 2 6 4 5 2 3 4 1 2
The biggest block of water would contain 20 units of water.
<pre>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace heavy_rain{
class Program{
static void Main(string[] args){
System.IO.StreamReader sr;
int n = 0, i = 0, result = int.MaxValue;
int[] buildingHeights = null;
try {
sr = new System.IO.StreamReader(args[0]);
String[] lines = new String[2];
String line = null;
while ((line = sr.ReadLine()) != null) {
lines[i++] = line;
}
n = int.Parse(lines[0]);
buildingHeights = new int[n];
String[] heights = lines[1].Split(' ');
for(int j = 0; j < heights.Length; j++) {
buildingHeights[j] = int.Parse(heights[j]);
}
Console.WriteLine(result);
}
catch (Exception e) {
System.Diagnostics.Trace.WriteLine(e.Message);
}
}
}
}
|
|
|
|
|
I don't think you'll find anyone here to do your homework for you. You'll have to do it yourself. But if you get stuck and have a specific question, come back and ask.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Member 13003743 wrote: The biggest block of water would contain 20 units of water. That does not make much sense. Ask your professor what is the connection is between height of building and amount of water.
|
|
|
|
|
Always assume that your teacher is reading this site, and will notice your attempt to cheat on your homework.
Expecting other people to do your work for you will not end well. How do you think that would go down in the real world, when you've got a real job and a mortgage to pay?
If you don't know how to start, then talk to your teacher.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Your main effort was to copy your assignment.
We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.
As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
Before we start, my textbook declares lgn as base two.
I only have one question, how did log2 become n (both highlighted in yellow in the picture)? Is it because log2 = 1, which is too small to even matter? Below is a link of the equations.
/Users/conrados/Desktop/20170207_091636000_iOS.jpg
|
|
|
|
|
The link to the picture won't work as that's your local Windows file (and it would have to be a proper web anchor).
This space for rent
|
|
|
|
|
Member 12986878 wrote: how did log2 become n Ask the person who wrote the textbook.
|
|
|
|
|
Member 12986878 wrote: how did log2 become n
when a log2 and an exp(n, 2) love each other very much...
|
|
|
|
|
What we read is meaningless.
Do not reformulate the question.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
Hello all,
I do need to send a motor from position A to B accelerating and decelerating accordingly to the defined allowed acceleration.
Constant acceleration.
Different starting speeds.
Different starting positions.
Different ending positions.
0 end speed.
I've tried to make my own which works perfectly when the values allow the motor to reach the maximum speed "plateau" but it is not working well when is not possible to achieve this and v0 (initial speed) and vf (end speed) are different.
Previous notes:
vmax = maximum allowed speed for the movement.
x0 = initial position.
xf = destination position.
v0 = initial speed.
vf = end speed (final).
ta = acceleration time from v0 to vmax.
da = distance to accelerate from v0 to vmax.
tf = braking time from vmax to vf.
df = braking distance from vmax to vf.
dist = total distance I want to move the motor xf-x0
The code I've used is:
LimitIterations = 1000
ta = Abs((vmax - v0) / a)
da = (v0 * ta) + (0.5 * a * ta * ta)
tf = Abs((vmax - vf) / a)
df = (vf * tf) + (0.5 * a * tf * tf)
If (da + df > dist + 0.000000001) Then
DistTotal = xf - x0 - da - df
RelAccDec = da / (da + df)
dist_corr_acc = DistTotal * RelAccDec
da = da + dist_corr_acc
dist_corr_dec = DistTotal * (1 - RelAccDec)
df = df + dist_corr_dec
taux = Sqr(da / (0.5 * a))
taux = (Sqr((2 * a * da) + (v0 * v0)) - v0) / a
vmax = v0 + (a * taux)
Do
ta = Abs((vmax - v0) / a)
da = (v0 * ta) + (0.5 * a * ta * ta)
tf = Abs((vmax - vf) / a)
df = (vf * tf) + (0.5 * a * tf * tf)
If (da + df > dist + 0.000000001) Then
vmax = vmax - 1
iterations = iterations + 1
If (iterations > LimitIterations) Then
ErrorID = 1
Exit Do
End If
Else
Exit Do
End If
Loop
End If
WRONG APPROACH EXPLANATIONS
The idea of that code was to find the maximum speed that can be reached given the specified conditions.
When the da + df are bigger than the total distance I'm doing a proportional reduction which approximates the vmax to it's desired/needed value.
The problem here I think is that part: I don't have to make a proportional reduction, I do need to find the position in which the acceleration movement and the deceleration movement are coincident once I will have this position then I should check the speed any of the movements has in that position. And that one should be vmax.
Now the issue is doing that...
I could use 0 as the starting position for the acceleration and xf as the starting position for the deceleration.
Both accelerations are the same (different signs).
I've seen examples of that when movements are not accelerated (the typical problem with two trains that leave the station) but nothing when the movements have constant acceleration.
Any hint, example, resource, formula that could solve it...
The solution
OK, at the end I've done it by algebra:
vp = v0 + (a0 * t0) vp = v1 + (a1 * t1) v0+(a0*t0) = v1+(a1*t1) t1=((v0-v1)+(a0*t0))/a1
d0 = (v00 * t0) + (0.5 * a0 * t0 * t0) d1 = (v01 * t1) + (0.5 * a1 * t1 * t1) D = (v00 * t0) + (0.5 * a0 * t0 * t0) + (v01 * t1) + (0.5 * a1 * t1 * t1)
And solve the quadratic equation to get the positive value (as we are speaking of time).
So.. this previous code substitutes the wrong approach method.
Thank you all,
modified 12-Feb-17 9:01am.
|
|
|
|
|
So at first you need to calculate the distance between both Points. That will be normally the Hypothenuse of a right-angled triangle.
Now you have to calculate the distance you need for speeding up your Motor. This could be calcuated with the final Speed (the Speed when you have finished the accelaration) and the acceleration itself.
The same you do for the decelaration.
If the distance for speeding up and the distance for speeding down is less than your complete distance then the difference is the way you drive with your final Speed and you will get a Trapezoid.
If the distance for speeding up and the distance for speeding down equal your complete distance then you will get a Triangle.
If the distance for speeding up and the distance for speeding down is more than your complete distance then you have to calculate the Point where both triangles meet. In this case your Motor doesn't reach the final Speed and your hull-curve will also be a triangle - but with a lower edge.
But you don't need to do an Interpolation ...
|
|
|
|
|
Hello Ralf,
Everything works.
I was simply trying to use a too high speed for a too short movement (totally obfuscated trying to get something impossible).
The only problem that I do still have is that I don't know how to efficiently find the maximum available speed.
What I'm doing is simple as:
Do
ta = Abs((vmax - v0) / a)
da = (v0 * ta) + (0.5 * a * ta * ta)
tf = Abs((vmax - vf) / a)
df = (vf * tf) + (0.5 * a * tf * tf)
If (da + df > dist) Then
If (v0 = vf) Then
taux = (Sqr((a * dist) + (v0 * v0)) - v0) / a
vmax = v0 + a * taux
Else
vmax = vmax - 1
End If
End If
Loop While (da + df > dist)
This works "perfectly":
- Avoiding the fact the maximum used speed will not be the purest maximum available.
- Avoiding the fact that it takes "ages" to find the maximum allowed speed for the current movement.
Any suggestion on how to find the maximum allowed speed in a faster way when v0 <> vf?
The initial data I do have is:
vmax (the one entered by the user it could be too high for what is possible).
x0 (initial position).
v0 (initial speed).
a (acceleration).
xf (end position).
vf (end speed (now we consider it always 0)).
Thank you.
modified 7-Feb-17 6:27am.
|
|
|
|
|
Perhaps this could be a Solution for you : (Pseudo-Code)
distance_with_v = x1 - x0 - s_Acc - s_Dec
if Distance_with_v < 0 then
Relation_Acc_Dec = s_Acc / (s_Acc + s_Dec)
DistanceCorrecting_Accelaration = Distance_with_v * Relation_Acc_Dec
da = s_Acc - DistanceCorrecting_Accelaration
DistanceCorrecting_Decelaration = Distance_with_v * (1 - Relation_Acc_Dec)
df = s_Dec - DistanceCorrecting_Decelaration
end if
|
|
|
|