hdu 2899
mxy终于学会求函数极值了。
先写一道板子。
#include <bits/stdc++.h>
using namespace std;
typedef double db;
const db eps = 1e-;
const db INF = 1e100;
const db delta = 0.98;
int sign(db k){
if (k>eps) return ; else if (k<-eps) return -; return ;
}
int cmp(db k1,db k2){return sign(k1-k2);}
int t;db y;
db get(db x){
return *x*x*x*x*x*x*x+*x*x*x*x*x*x+*x*x*x+*x*x-y*x;
}
db x[];
db random(){
return (rand()&?:-)*rand()*1.0/;
}
void init(){
for(int i=;i<;i++) x[i]=abs(random())*;
}
db sa(){
db ans = INF;
db t=;
while (t>eps){
for(int i=;i<;i++){
db tmp = get(x[i]);
for(int j=;j<;j++){
db _x=x[i]+random()*t;
if(cmp(_x,)>=&&cmp(_x,)<=){
db f = get(_x);
if(tmp>f)
x[i]=_x;
}
}
}
t*=delta;
}
for(int i=;i<;i++)
ans=min(ans,get(x[i]));
return ans;
} int main(){
ios::sync_with_stdio(false);
scanf("%d",&t);
while (t--){
scanf("%lf",&y);
init();
printf("%.4f\n",sa());
}
}
hdu 2899的更多相关文章
- hdu 2899 Strange fuction
http://acm.hdu.edu.cn/showproblem.php?pid=2899 Strange fuction Time Limit: 2000/1000 MS (Java/Others ...
- (二分搜索 )Strange fuction -- HDU -- 2899
链接: http://acm.hdu.edu.cn/showproblem.php?pid=2899 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- hdu 2899 Strange fuction (二分)
题目链接:http://acm.hdu.edu.cn/showproblem.pihp?pid=2899 题目大意:找出满足F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x ( ...
- hdu 2899 Strange fuction——模拟退火
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2899 还可三分.不过只写了模拟退火. #include<iostream> #include& ...
- hdu 2899 Strange fuction —— 模拟退火
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2899 模拟退火: 怎么也过不了,竟然是忘了写 lst = tmp ... 还是挺容易A的. 代码如下: # ...
- ACM : HDU 2899 Strange fuction 解题报告 -二分、三分
Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- HDU 2899 Strange fuction 【三分】
三分可以用来求单峰函数的极值. 首先对一个函数要使用三分时,必须确保该函数在范围内是单峰的. 又因为凸函数必定是单峰的. 证明一个函数是凸函数的方法: 所以就变成证明该函数的一阶导数是否单调递增,或者 ...
- hdu 2899(数学基础+二分)
题意:给了你一个函数,然后给了你x的变化范围,让你求出函数的最小值. 分析:它让你求的是函数的最小值,所以我们可以先对函数求导,得到的导数就可以判断函数的单调性了,求出导数后,我们发现如果函数的导数是 ...
- hdu 2899 hdu 3400 三分/几何
hdu2899 : 水提,直接三分,事实上求导后二分也能够. #include<iostream> #include<cstdio> using namespace std; ...
- hdu 2899 Strange fuction 模拟退火
求 F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)的最小值 模拟退火,每次根据温度随机下个状态,再根据温度转移 #include& ...
随机推荐
- shell之磁盘容量检查,配合crontab可以定时清理磁盘
我的做法: !/bin/bashAvailable=`df -k | sed -n 2p | awk '{print $4}'`if [ $Available -eq 0 ];then ...
- 透明Panel
unit TransparentPanel; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Varia ...
- x264阅读记录-3
14. x264_macroblock_encode函数-1 这个函数主要根据已经选定的模式来对宏块残差进行编码. )如果是P_SKIP模式,那么调用x264_macroblock_encode_ ...
- ABAP技术总结
SAP ——ABAP/4 技术总结 V3.0 2014-10-14 --江正军 1. 1.1. 1.1.1. 1.2. 1.3. 1.4. 1.5. 1.6. 1.7. 1.7.1. 1.7.2. ...
- idea java9以及以上 出现找不到class的情况
https://juejin.im/entry/59cdb7e65188255d3448fc64 https://blog.jetbrains.com/idea/2017/03/support-for ...
- PHPStrom激活方法
直接用浏览器打开 http://idea.lanyus.com/ 点击页面中的“获得注册码”, 然后在注册时切换至Activation Code选项,输入获得的注册码一长串字符串 如果提示红字体信息, ...
- 【转】33 个 2017 年必须了解的 iOS 开源库
1.IGListKit,作者是Instagram Engineering Instagram 程序员做的,IGListKit 是数据驱动的 UICollectionView 框架,为了构建快速和可扩展 ...
- FreeBie—免费设计师专用素材网
FreeBie—免费设计师专用素材网 网站地址: https://freebiesupply.com/ 网站分类: 素材 浏览次数: 192 标签: 设计素材 Freebie Supply 是国外一家 ...
- linux内存管理之malloc、vmalloc、kmalloc的区别
kmalloc kzalloc vmalloc malloc 和get_free_page()的区别 一.简述 1. kmalloc申请的是较小的连续的物理内存,虚拟地址上也是连续的.kmalloc和 ...
- What’s new for Spark SQL in Apache Spark 1.3(中英双语)
文章标题 What’s new for Spark SQL in Apache Spark 1.3 作者介绍 Michael Armbrust 文章正文 The Apache Spark 1.3 re ...