HDU - 2899 Strange fuction(三分)

ACM经典题目A+B The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000 立即下载

Now, here is a fuction: 
  F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100) 
Can you find the minimum value when x is between 0 and 100.

Input

 The first line of the input contains an integer T(1<=T<=100) which means the number of test cases. Then T lines follow, each line has only one real numbers Y.(0 < Y <1e10)

Output 

 Just the minimum value (accurate up to 4 decimal places),when x is between 0 and 100.

Sample Input

2
100
200

Sample Output

-74.4291
-178.8534

    题目大意就是求0\leq x\leq 100时函数的最小值,用三分的人比较少,但三分在求最值问题上更直观,更方便。

    三分的主要思想就是将函数线分成三份(在\frac{1}{3}和\frac{2}{3}处切分),不断舍弃远离极值的那一部分。

    上代码

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

double y;
double fx(double x){
	return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x;
}

int main() {
	int t;
	double midl,midr,left,right;
	cin>>t;
	while(t--){
		left=0;
		right=100;
		cin>>y;
/*******************三分********************/		
		while((right-left)>=1e-6){
			midl=(left+right)/2;
			midr=(midl+right)/2;
			double cmidl=fx(midl);
			double cmidr=fx(midr);
			if(cmidl<cmidr)//舍弃远离最小值的那一端 
				right=midr;
			else
				left=midl;
		}
		printf("%.4lf\n",fx((left+right)/2));//将得到的x值代入方程中即为结果           
	}
	return 0;
}

 

Claude桌面端安装失败?Retrying无限重试终极解决方案(亲测有效) Claude桌面端安装卡在Retrying并非网络问题,而是安装器下载源异常导致。本文提供已验证方案:一条命令即可解决问题🚀 阅读详情

相关推荐

ESP32+LED12864液晶屏实战:手把手教你显示中文与自定义图标(附完整代码)

本文详细介绍了如何使用ESP32单片机驱动带字库的LED12864液晶屏,实现中文显示与自定义图标。从硬件选型、接线方案到驱动编写、字库解析,提供了完整的实战代码与优化技巧,并最终构建了一个智能家居控制面板的完整示例项目。

weixin_29212867的博客 146

二分或三分查找:C - Strange fuction 解题报告

Strange fuction Description Now, here is a fuction:    F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 Can you find the minimum value when x is between 0 and 100. Input The first line o

并非所有流浪者都迷失了自我 714

[原创]Linux 802.11n CSI tool Monitor模式

Linux 802.11n CSI tool Monitor模式 使用AP模式的缺陷在于ping 命令速度比较慢,且不能精确控制发送的参数,比如接收的包数量是不可控的。Monitor模式可以调制发送速率、发包数量、发送天线个数、HT模式、short/long guard interval等等,因此调通Monitor模式是必须的。期间参考了博主沃一德的CSI Tool安装使用讲解,对他的工作表示感...

u014645508的博客 1万+

#2020.01.14训练题解#二分入门(D题)

题源HDU-2199 HDU-2199-Can you solve this equation? Description Now,given the equation 8x^4 + 7x^3 + 2x^2 + 3x + 6 == Y,can you find its solution between 0 and 100; Now please try your lucky. Input Th...

薄荷糖·琳的博客 303

CST仿真实例001:圆极化平板天线仿真

CST仿真实例001:圆极化平板天线仿真实例

weixin_47638568的博客 1万+

告别玄学调试:用STM32CubeMX和逻辑分析仪搞定DP83848的RMII与SMI接口

本文详细介绍了如何使用STM32CubeMX和逻辑分析仪调试DP83848的RMII与SMI接口,帮助开发者超越表象,直接观察底层通信波形。通过实战案例和高级调试技巧,解决常见问题如时钟偏移、信号完整性等,提升网络接口的稳定性和可靠性。

weixin_30752699的博客 299

题解-equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y;

Problem DescriptionNow,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,can you find its solution between 0 and 100;&lt;br&gt;Now please try your lucky. InputThe first line of the input contain...

二喵君的博客 5707

uniapp map地图实现marker聚合点,并点击marker触发事件

【代码】uniapp map地图实现marker聚合点,并点击marker触发事件。

weixin_44705979的博客 5437

Strange fuction

Problem Description Now, here is a fuction:   F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 &lt;= x &lt;=100) Can you find the minimum value when x is between 0 and 100.     Input The first line of the...

薄荷糖 964

“华为杯”研究生数学建模竞赛2016年-【华为杯】A题:多无人机协同任务规划

题分别求解,保证了攻击方无人机滞留在防御方雷达有效探测范围内的时间总和最小,接着,通过提出巡检待命无人机的设想,型无人机携带炸弹的具体清单和攻击的目标清单),保证攻击方的无人机滞留防御方雷。在使用基于贪心算法的覆盖法时,覆盖的目标点中必须首先不含配备雷达站的目标点。步优化保证攻击方的无人机滞留防御方雷达有效探测范围内的时间总和最小,需首先。的“灵巧”炸弹,采用抛投方式对地攻击,即投放后炸弹以飞机投弹时的速度作抛物。运动,当炸弹接近目标后,可主动寻的攻击待打击的目标,因此炸弹落点位于目标中。

getusushu的博客 1036

2026年华为od机试真题题库

OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)OD统一考试(E卷)

面试高手的博客 19万+

【2199】Can you solve this equation?

【2199】Can you solve this equation? Problem Description Now,given the equation 8x^4 + 7x^3 + 2x^2 + 3x + 6 == Y,can you find its solution between 0 and 100; Now please try your lucky. Input The first line of the input contains an integer T(1<=T<=10

weixin_49646622的博客 223

MATLAB - 激光雷达 - 相机联合标定(Lidar-Camera Calibration)

激光雷达传感器和相机通常在自动驾驶应用中结合使用,因为激光雷达传感器收集三维空间信息,而相机则以二维图像捕捉空间的外观和纹理。您可以融合来自这些传感器的数据来改进物体检测和分类。激光雷达-相机标定可以估算出一个变换矩阵,给出两个传感器之间的相对旋转和平移。在进行激光雷达-相机数据融合时,您可以使用该矩阵。本图说明了激光雷达和相机标定 (LCC) 过程的工作流程,我们使用棋盘格作为标定对象。我们从激光雷达和相机数据中提取棋盘角和平面,然后在它们的坐标系之间建立几何关系,进行标定。

机器人控制与仿真应用 7371

hdu 2899 Strange fuction(三分)

hdu 2899 Strange fuction(三分)

1749

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

【hdu2899】Strange fuction——三分

题目: Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5360    Accepted Submission(s): 3832 Problem Description Now

CFhM_R's Blog 552

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

HDU -2899 Strange fuction(三分)

Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description Now, here is a fuction: F(x) = 6 * x7+8*x6+7x3+5*x2-yx (0 <= x <=100) ...

名字太长容易被发现并打死 263

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

HDU 2899 Strange fuction——三分搜索

链接 : http://acm.hdu.edu.cn/showproblem.php?pid=2899 题意 : 给定一个函数,判断其最小值。 分析: 首先回顾一下,单调函数查找特定的值,是通过二分搜索得到的。 即 l = min, r = max. mid = (l + r) /2 此处是下界。 mid = l + (l+r)/2 是上界。 三分搜索,则针对的是凹凸函数。 如图: 其中 ...

彤云望月 267

HDU 2899 Strange fuction(二分,三分)

Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 80    Accepted Submission(s): 62 Problem Description Now,

其实我是C先生--的博客 561

HDU2899 Strange fuction【三分】

Problem Description Now, here is a fuction:   F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 &lt;= x &lt;=100) Can you find the minimum value when x is between 0 and 100.   Input The first line of the in...

独钓门前月 392

hdu 2899 Strange fuction 【二分,三分】

hdu 2899 Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3212    Accepted Submission(s): 2351 Problem Description N

柚的个人技术博客 689

hdu2899 Strange fuction 三分搜索

Now, here is a fuction:   F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 Can you find the minimum value when x is between 0 and 100. 题解:函数是凸性的,用二分搜索需要做特殊处理,求解凸性函数用三分搜索是比较方便的。 类似二分的定义Left和Right,mid =

ccsu_cherish 664

hdu2899 Strange fuction(二分兼三分)

好久没做数学导数都想不过来了= =,本题是F''(x)恒大于0,所以F'(x)递增,零点以前的F(x)都是减函数,所以以零点为判断标准就行了。 而且事实证明无法用宏定义二变量函数。 #include #include #include #include #include #include using namespace std; const int N = 100; const

Iguodala的博客 408

Strange fuction HDU - 2899(三分)

Strange fuction 题目链接:HDU - 2899 题意: F(x) =...

Sirius_han的博客 260

【HDU 2899】Strange fuction(三分)

 Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6986    Accepted Submission(s): 4870 Problem Description Now, her

FSMM_blog 330

HDU 2899 - Strange fuction (三分)

题目:https://vjudge.net/contest/312328#problem/A 题意:二分 找函数的最小值 (三分? 学到的 hhh ) mid and midmid #include<bits/stdc++.h> using namespace std; int n,a; double f(double x) { ...

weixin_30394251的博客 138

Hdu 2899 Strange fuction(二分三分可做,模拟退火解法)

题意:计算F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 分析:求导发现0~100内为凹函数,那么可以直接二分导数或者三分原函数, 这里写一下模拟退火的做法,每次左右找到较低函数值并转移x,控制一下精度,和二分三分差不多, 只是写法不一样。 #include #include #include #include #include #include

每一次AC都是一种感动 1033
上一篇: CSUACM 1976: 搬运工小明(二分)
下一篇: HDU - 1027 - Ignatius and the Princess II(STL)
LangoRow
博客等级 码龄8年 2粉丝 7原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值