An algorithm !! The existing range is $ start -- $ end (for example, 5--10 ).
Give a variable $ param:
If $ param <$ start, $ param = $ start
If $ param> $ end, $ param = $ end
No logic algorithms such as if else and ternary (although simple and efficient)
Realistic mathematical algorithms
Reply to discussion (solution)
Uncertainty
This algorithm does not exist (comparison is not used), and bitwise operations may increase the speed for explanatory languages.
Even if there is, there must be two multiplication and one division, which is time-consuming than if-else.
Therefore, it does not exist.
Example: 5--10 (x-y)
A = x-z
B = y-z
Assume that the number of judgments is 1 (z)
Because a is greater than 0, B is greater than 0. So z = x = 5.
Assume that the number of judgments is 11 (z)
Because a is less than 0, B is less than 0. So z = y = 10.
Assume that the number of judgments is 6 (z)
Because a is less than 0, B is greater than 0. So it is not true.
It hurts
There is no answer if you try or combine it with a different modulo rounding...
We will discuss the possibility of implementing this algorithm.
I'm looking for an algorithm. this is really not = _ =...
This algorithm does not exist (comparison is not used), and bitwise operations may increase the speed for explanatory languages.
Even if there is, there must be two multiplication and one division, which is time-consuming than if-else.
Therefore, it does not exist.
The formula itself is estimated to exist. No judgment
However, there is really no very fast Formula. I just deduced it and found that multiplication/division is required.
Why did I swallow my 4 th floor?
I also tried multiple combinations of operations and never got results.
Discuss the possibility of implementation
Derivation process
The formula itself is estimated to exist. No judgment
However, there is really no very fast Formula. I just deduced it and found that multiplication/division is required.
X = 5 (y <= 5)
X = y (y in the range [5, 10)
X = 10 (y> = 10)
------------------------------------------------------------
The main figure draws a coordinate chart, which is basically equivalent to a lightning curve (), which was never seen in Ry ..
|
|
|
/(10)
/
/
| (5)
|
|
|
|
Can it be implemented without comparison ?? I doubt
A, B E [5, 10]
X = a + 1;
X = B-1;
And Many values ....
Passing through php should be able to do it!
This is not a good math. I cannot think of it for the moment. in the absence of any range (that is, the absence of if), the f (x) solution... waiting for the math Emperor...
Min can be used. isn't max very simple?
$param = 4;echo min(max($param,5),10);
That's all.
Yes. Min and max...
Everybody, continue ..
I learned
But I think the max min mechanism should be implemented internally using logical operations.
A word awakened a dreamer
Function getnum ($ param, $ start, $ end)
{
$ Min = min ($ param, $ start, $ end );
$ Max = max ($ param, $ start, $ end );
If ($ min = $ param)
{
$ Param = $ min;
}
If ($ max = $ param)
{
$ Param = $ max;
}
Return $ param;
}
Min can be used. isn't max very simple?
PHP code
$ Param = 4;
Echo min (max ($ param, 5), 10 );
That's all.
= _ =...
Foolbirdflyfirst has a code. You still write
A word awakened a dreamer
Function getnum ($ param, $ start, $ end)
{
$ Min = min ($ param, $ start, $ end );
$ Max = max ($ param, $ start, $ end );
If ($ min = $ param)
{
$ Param = $ min;
}
If ($ max = $ param)
{
$ Param ......
Respect the fruits of others' work.
= _ =...
Foolbirdflyfirst has a code. You still write
Reference the reply from jasmine_xiaocao on the 21st floor:
A word awakened a dreamer
Function getnum ($ param, $ start, $ end)
{
$ Min = min ($ param, $ start, $ end );
$ Max = max ($ param, $ start, $ end );
If ($ mi ......
This classmate is very serious about your problem ~~
Respect the fruits of others' work.
Reply by referencing ci1699 on the 22nd floor:
= _ =...
Foolbirdflyfirst has a code. You still write
Reference the reply from jasmine_xiaocao on the 21st floor:
A word awakened a dreamer
Function getnum ($ param, $ start, $ end)
{
$ Min = min ($ param, $ start, $ end );
......
What does the landlord mean ???
This classmate is very serious about your problem ~~
Reference the reply from jasmine_xiaocao on the 23rd floor:
Respect the fruits of others' work.
Reply by referencing ci1699 on the 22nd floor:
= _ =...
Foolbirdflyfirst has a code. You still write
Reference the reply from jasmine_xiaocao on the 21st floor:
A word awakened a dreamer
Function getnum ($ param, $ start ,......
I can't use if else ~ What does the landlord mean ???
Reference the reply of mr_merlin on the 24th floor:
This classmate is very serious about your problem ~~
Reference the reply from jasmine_xiaocao on the 23rd floor:
Respect the fruits of others' work.
Reply by referencing ci1699 on the 22nd floor:
= _ =...
Foolbirdflyfirst has a code. You still write
Reference the reply from jasmine_xiaocao on the 21st floor:
Waking up a dream ......
Isn't it enough ?? Then I am wrong ....
I can't use if else ~ Reference the reply from jasmine_xiaocao on the 25 th floor:
What does the landlord mean ???
Reference the reply of mr_merlin on the 24th floor:
This classmate is very serious about your problem ~~
Reference the reply from jasmine_xiaocao on the 23rd floor:
Respect the fruits of others' work.
Reply by referencing ci1699 on the 22nd floor:
= _ =...
Foolbirdflyfir ......
Min can be used. isn't max very simple?
PHP code
$ Param = 4;
Echo min (max ($ param, 5), 10 );
That's all.
Yes. what if min or max is unavailable?
I haven't figured it out after reading it for a long time.
It seems that my algorithm has a poor level.
Learning
function foo($a, $b, $c) {Return (((($c-$a) + (($c-$a) >> 31)) ^ (($c-$a) >> 31)) - ((($c-$b) + (($c-$b) >> 31)) ^ (($c-$b) >> 31)) + $a + $b) / 2;}echo foo(20, 30, 50); // 30
This does not use any function pulling.
What I got from the search,
Algorithms need to be studied.
Abs is easy to understand.
Reference the reply from foolbirdflyfirst on the 17th floor:
Min can be used. isn't max very simple?
PHP code
$ Param = 4;
Echo min (max ($ param, 5), 10 );
That's all.
Yes. what if min or max is unavailable?
I don't know either... #30 talents. Haha
I don't know either.
Convert the number to the lower-bound hexadecimal number and the upper-bound hexadecimal number respectively,
The result is
Example: (5, 10, x) x = 8
X1 = 13 (mod5)
X2 = 08 (mod10)
Answer = (x1msb ⊙ x2msb) * (x1msb * 5 + x2msb * 10) + (x1msb xor x2msb) * x
Here, x1msb x2msb requires the result of high integer division to obtain the binary 0, 1
I don't know what you're thinking
Watching ....
Passing.
Is there an algorithm like this?
X = 5 (y <= 5)
X = y (y in the range [5, 10)
X = 10 (y> = 10)
------------------------------------------------------------
The main figure draws a coordinate chart, which is basically equivalent to a lightning curve (), which was never seen in Ry ..
|
|
|
/(10)
/
/
| (5)
|
|
|
|
As stated on the 9th floor, if the landlord wants a mathematical algorithm
?? ?? ?? ?? ?? ?? ??
/
/
/
/
/
?? ?? ?? ?? ?? ?? ??
Similar function curves have never been seen yet,
It can only be a piecewise function, divided into three sections, so it seems that if else is used.
-How did my graph become like this ....
The curve is similar to the y-axis symmetric graph of Z. should this be only a piecewise function? Because it is not smooth at all.
Reference the reply from foolbirdflyfirst on the 9th floor:
X = 5 (y <= 5)
X = y (y in the range [5, 10)
X = 10 (y> = 10)
------------------------------------------------------------
The main figure draws a coordinate chart, which is basically equivalent to a lightning curve (), which was never seen in Ry ..
|
|
......
public static int get(int start, int end, int param) { param -= start; param &= (int)(((uint)param) >> 31) - 1; param += start; param -= end; param &= (int)((((uint)param) >> 31) ^ 1) - 1; return param += end; } public static int get1(int start, int end, int param) { return new int[] { end, param, start, start }[(((uint)(param - start) >> 30) & 2) | ((uint)(param - end) >> 31)]; }
You can only calculate positive values with the symbol bit. Otherwise, you must extend the int value to long.
I don't know if this is what the landlord wants.
int foo(int start, int end, int param){int tmp[2];tmp[0] = param;tmp[1] = start;param = tmp[(param-start)>>(sizeof(int)*8-1)];tmp[1] = end;param = tmp[(end-param)>>(sizeof(int)*8-1)];return param;}
Param = (start + end)-abs (start-end)/2, where abs () is the absolute value operation.
Param = (abs (param-start)-abs (param-end) + start + end)/2;
I cannot understand it ·
I don't know.