蓝桥杯小白赛第六期 6.计算方程 知识点:数学,二分

6.计算方程【算法赛】 - 蓝桥云课 (lanqiao.cn)

求x的最大范围

在不考虑 <math xmlns="http://www.w3.org/1998/Math/MathML"> log ⁡ k x \log_{k}{x} </math>logkx 给 <math xmlns="http://www.w3.org/1998/Math/MathML"> x \sqrt{x} </math>x 增值的情况下:

因此,x最大不会超过m的平方+1,即 <math xmlns="http://www.w3.org/1998/Math/MathML"> x < = 1 e 8 x<=1e8 </math>x<=1e8。


现在我们再看看看 <math xmlns="http://www.w3.org/1998/Math/MathML"> log ⁡ k x \log_{k}{x} </math>logkx会对x增值有多大影响: 因为k是样例输入的值,因为log函数底越小函数增长越快,我们假设k是2(1被排除了),这样求出来的 <math xmlns="http://www.w3.org/1998/Math/MathML"> log ⁡ k x \log_{k}{x} </math>logkx值最大。

<math xmlns="http://www.w3.org/1998/Math/MathML"> log ⁡ k x \log_{k}{x} </math>logkx

<math xmlns="http://www.w3.org/1998/Math/MathML"> log ⁡ 2 1 e 8 \log_{2}{1e8} </math>log21e8

<math xmlns="http://www.w3.org/1998/Math/MathML"> 2 n = x 2^n=x </math>2n=x

<math xmlns="http://www.w3.org/1998/Math/MathML"> 2 n = 1 e 8 2^n=1e8 </math>2n=1e8

<math xmlns="http://www.w3.org/1998/Math/MathML"> n = 26 n=26 </math>n=26

因此 <math xmlns="http://www.w3.org/1998/Math/MathML"> log ⁡ k x = 26 \log_{k}{x}=26 </math>logkx=26

26可以忽略不计。

因此我们可以枚举x最大到1e8就可以了。

code

js 复制代码
#include<bits/stdc++.h>
using namespace std;

int k,m;

int check(int x)
{
  if(sqrt(x)+floor(log(x)/log(k))-m>0)return true;
  return false;	
}
void sovel()
{
	cin>>k>>m;
	
	//二分查找x
	
	int l=1,r=1e8;
	while(l<r)
	{
	   int mid=(l+r)>>1;
	   if(check(mid))r=mid;  //如果mid大了,说明x在左半边
	   else l=mid+1;	 //如果mid小了,说明x在右半边
	} 
	cout<<l<<endl;
}
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t; cin >> t;
    while (t--) {
        sovel();
    }
  return 0;	
} 
相关推荐
子春一8 分钟前
Flutter for OpenHarmony:构建一个 Flutter 四色猜谜游戏,深入解析密码逻辑、反馈算法与经典益智游戏重构
算法·flutter·游戏
人道领域34 分钟前
AI抢人大战:谁在收割你的红包
大数据·人工智能·算法
TracyCoder1231 小时前
LeetCode Hot100(34/100)——98. 验证二叉搜索树
算法·leetcode
A尘埃1 小时前
电信运营商用户分群与精准运营(K-Means聚类)
算法·kmeans·聚类
power 雀儿2 小时前
掩码(Mask)机制 结合 多头自注意力函数
算法
会叫的恐龙2 小时前
C++ 核心知识点汇总(第六日)(字符串)
c++·算法·字符串
小糯米6012 小时前
C++顺序表和vector
开发语言·c++·算法
We་ct2 小时前
LeetCode 56. 合并区间:区间重叠问题的核心解法与代码解析
前端·算法·leetcode·typescript
Lionel6892 小时前
分步实现 Flutter 鸿蒙轮播图核心功能(搜索框 + 指示灯)
算法·图搜索算法
小妖6663 小时前
js 实现快速排序算法
数据结构·算法·排序算法