An algorithm !! Existing range: $ start -- $ end & nbsp; (for example, 5--10 ). Give a variable $ param: if $ param & lt; $ start & nbsp; then $ param = $ start if $ param & gt; $ end & nbsp; then $ param = $ end does not require if & nbsp; e to calculate 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)
To be realistic, share the following mathematical algorithms: $ end ??... 'Data-pics = ''>
------ Solution --------------------
Can it be done?
The answer is yes. Otherwise, I won't pin him up.
Let me start with a discussion.
function foo($a, $b, $c) {
$f1 = -(($c - $a) >> 31);
$f2 = -(($b - $c) >> 31);
$f3 = 1 ^ ($f1 + $f2);
return $f1 * max($a, $c) + $f2 * min($b, $c) + $f3 * $c;
}
echo foo(5, 10, 3); //5
echo foo(5, 10, 8); //8
echo foo(5, 10, 13); //10
------ Solution --------------------
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.
------ Solution --------------------
Reference:
Can it be done?
The answer is yes. Otherwise, I won't pin him up.
Let me start with a discussion.
PHP code
Function foo ($ a, $ B, $ c ){
$ F1 =-($ c-$ a)> 31 );
$ F2 =-($ B-$ c)> 31 );
$ F3 = 1 ^ ($ f1 + $ f2 );
Return $ f1 * max ($ a, $ c) + $ f2 * min (......
I don't understand PHP... but the answer is too obvious.
So write a C version int ..
#include
int middle(int a,int b,int c)
{
long long la=a;
long long lb=b;
long long lc=c;