A 清楚姐姐学信息论【2023牛客寒假算法基础集训营4】

A 清楚姐姐学信息论

原题链接

题意

给出\(a,b\),问当\(a,b\)的值为多少时\(a^b>b^a\)

思路

\(a^b>b^a\)
\(blna>alnb\)
\(\frac{lna}{a}>\frac{lnb}{b}\)
\(f(x) = \frac{lnx}{x}\)
\(f'(x) = \frac{1-lnx}{x^2}\)
\(f'(x)=0\)
\(x=e\)
\(0<x<e\)\(f'(x)>0\)
\(x>e\)\(f'(x)<0\)
\(f(x)在(0,e)单调递增,在(e,+\infty)单调递减\),极大值\((e,\frac{1}{e})\)
image

有三种情况

  1. \(a>e\),\(b>e\) ->单调递减->min(a,b)
  2. \(a<e\),\(b<e\) ->单调递增->max(a,b)
  3. \(min(a,b) < e\) , \(max(a,b) > e\)
    由于题目范围\(2\le a,b \le 10^9\)
    只需讨论\(min(a,b)=2\)即可
    即当\(2<max(a,b)<=4\) ->\(2\)
    \(max(a,b)\ge >4\) ->\(max(a,b)\)

image

代码

点击查看代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;

#define X first
#define Y second

typedef long long LL;
const char nl = '\n';
const int N = 1e6+10;
int n,m;

void solve(){
    int a,b;
    cin >> a >> b;
    if(a > 2 && b > 2)cout << min(a,b);
    else if(a == 2 && b == 2)cout << 2;
    else{
        if(max(a,b) < 4)cout << max(a,b);
        else cout << min(a,b);
    }
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);

	solve();
}

补充

问题的背景是进制效率
x进制和y进制分别使用\(x \cdot y\)张号码牌时x进制能够表示的数字数目大于y进制,则称x进制的信息表示效率大于y进制
简单来说,在两种进制每个位数都被填满的情况下,相同数目个数的数字能表式的数字更大则效率越高
透过题目我们可以得到

  1. 对于整数进制而言,进制效率:\(3>2=4>5>6>7>...\)
  2. 理论上e进制效率最高
点击查看代码
	if(min(a,b) == 2 && max(a,b)==3)cout << 3;	//只有一种情况是例外
	else cout << min(a,b);	//否则都是进制数小的效率越高

posted @ 2023-01-31 18:39  Keith-  阅读(15)  评论(0编辑  收藏  举报