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

A 清楚姐姐学信息论

原题链接

题意

给出a,b,问当a,b的值为多少时ab>ba

思路

ab>ba
blna>alnb
lnaa>lnbb
f(x)=lnxx
f(x)=1lnxx2
f(x)=0
x=e
0<x<ef(x)>0
x>ef(x)<0
f(x)(0e)(e,+),极大值(e,1e)
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
    由于题目范围2a,b109
    只需讨论min(a,b)=2即可
    即当2<max(a,b)<=4 ->2
    max(a,b)≥>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进制分别使用xy张号码牌时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 @   Keith-  阅读(18)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示