Forgot password
 Register account
View 1784|Reply 6

[函数] 第二大的数

[Copy link]

3200

Threads

7827

Posts

52

Reputation

Show all posts

hbghlyj posted 2019-7-10 23:34 |Read mode
Last edited by hbghlyj 2022-6-27 17:19用绝对值函数和四则运算的有限次复合表示$n$个实数中第二大的数(有多种表示)

a,b中第二大的数=$\frac{a+b-|a-b|}2$=$\frac{2ab}{a+b+|a-b|}$
a,b,c中第二大的数=$\frac{2a+2b+|a+b-|a-b|-2c|-|a+b+|a-b|-2c|}4$
=$-\frac{8abc}{{(a-b)^2-4c(a+b)-\left| {a - b} \right|( - \left| {a + b - 2c - \left| {a - b} \right|} \right| + a + b - 2c)}}$

673

Threads

110K

Posts

218

Reputation

Show all posts

kuing posted 2019-7-10 23:55
代码弄不好,干脆就贴图吧……

764

Threads

4672

Posts

27

Reputation

Show all posts

isee posted 2019-7-11 14:57
回复 5# hbghlyj

超长公式,一般用 split 环境。

不过,在论坛,可以直接用\\强行拆分。

461

Threads

957

Posts

4

Reputation

Show all posts

青青子衿 posted 2022-6-27 20:03
It will only have two situations: interval [min(a,b), max(a,b)]intersects with [min(c,d), max(c,d)] or not.
leetcode.com/problems/reverse-subarray-to-max … ion-with-explanation

3200

Threads

7827

Posts

52

Reputation

Show all posts

original poster hbghlyj posted 2022-6-27 23:33
a,b,c,d中第二大的数=max(min(max(a,b),max(c,d)),min(a,b),min(c,d))
#include <stdio.h>
int max(int a, int b)
{
    return (a>b)?a:b;
}
int min(int a, int b)
{
    return (a<b)?a:b;
}
int max3(int a, int b, int c)
{
    return max(max(a,b),c);
}
int secondLargest(int i[4])
{
    return max3(min(max(i[0],i[1]),max(i[2],i[3])),min(i[0],i[1]),min(i[2],i[3]));
}
int main()
{
    int ls[24][4]={{1, 2, 3, 4}, {1, 2, 4, 3}, {1, 3, 2, 4}, {1, 3, 4, 2}, {1, 4, 2, 3}, {1, 4, 3, 2}, {2, 1, 3, 4}, {2, 1, 4, 3}, {2, 3, 1, 4}, {2, 3, 4, 1}, {2, 4, 1, 3}, {2, 4, 3, 1}, {3, 1, 2, 4}, {3, 1, 4, 2}, {3, 2, 1, 4}, {3, 2, 4, 1}, {3, 4, 1, 2}, {3, 4, 2, 1}, {4, 1, 2, 3}, {4, 1, 3, 2}, {4, 2, 1, 3}, {4, 2, 3, 1}, {4, 3, 1, 2}, {4, 3, 2, 1}};
    for (int i=0; i<24; i++) {
        if(secondLargest(ls[i])==3){printf("%d success\n",i+1);}else{printf("%d fail\n",i+1);}
    }
    return 0;
}
输出
1 success
2 success
3 success
4 success
5 success
6 success
7 success
8 success
9 success
10 success
11 success
12 success
13 success
14 success
15 success
16 success
17 success
18 success
19 success
20 success
21 success
22 success
23 success
24 success

3200

Threads

7827

Posts

52

Reputation

Show all posts

original poster hbghlyj posted 2022-6-28 00:12
$A=\{a_1,⋯,a_n\}$
$A_i=A∖\{a_i\}$
$b_i$为$n-1$元集$A_i$中第二大的数
则$\max(b_1,⋯,b_n)$为$A$中第二大的数

$a,b$中第二大的数$\min(a,b)$
$a,b,c$中第二大的数$\max(\min(a,b),\min(b,c),\min(c,a))$
$a,b,c,d$中第二大的数\begin{aligned}
\max(\max(\min(a,b),\min(b,c),\min(c,a)),\\
\max(\min(a,b),\min(b,d),\min(d,a)),\\
\max(\min(a,c),\min(c,d),\min(d,a)),\\
\max(\min(b,c),\min(c,d),\min(d,b)))
\end{aligned}⋯⋯如此一直下去

3200

Threads

7827

Posts

52

Reputation

Show all posts

original poster hbghlyj posted 2022-6-28 00:37
$n$个实数$a_1,⋯,a_n$中第二大的数=
$$\max\left\{\min\{a_i,a_j\}\middle|1⩽i<j⩽n\right\}$$
例如$a,b,c,d$中第二大的数=\begin{aligned}
\max(\min(a,b),\min(a,c),\min(a,d),\\
\min(b,c),\min(b,d),\min(c,d))
\end{aligned}

Quick Reply

Advanced Mode
B Color Image Link Quote Code Smilies
You have to log in before you can reply Login | Register account

$\LaTeX$ formula tutorial

Mobile version

2025-7-15 15:20 GMT+8

Powered by Discuz!

Processed in 0.012018 seconds, 23 queries