题目:http://acm.hdu.edu.cn/showproblem.php?pid=2899

还可三分。不过只写了模拟退火。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<ctime>
#include<cmath>
#include<cstdlib>
#define db double
using namespace std;
const int nx[]={,,,,,},c[]={,,,,,};
const db dc=0.997,eps=1e-;
int T;
db y,ans,px;
db pw(db x,int k){db ret=;while(k){if(k&)ret*=x;x*=x;k>>=;}return ret;}
db calc(db x)
{
db ret=;
for(int i=;i<=;i++)ret+=c[i]*pw(x,nx[i]);
ret-=y*x; return ret;
}
db gtrd(db T){return (rand()*-RAND_MAX)*T;}
void SA(db T)
{
db x0=px,pr=ans,x,cr;
while(T>eps)
{
x=x0+gtrd(T); if(x>)x=; if(x<)x=; cr=calc(x);
if(cr<pr||exp((cr-pr)/T)*RAND_MAX<rand())
{
if(cr<ans)ans=cr,px=x;
x0=x;pr=cr;
}
T*=dc;
}
}
int main()
{
srand(time());
scanf("%d",&T);
while(T--)
{
scanf("%lf",&y);
px=;ans=calc(px);
for(int i=;i<=;i++)SA();
printf("%.4lf\n",ans);
}
return ;
}

hdu 2899 Strange fuction——模拟退火的更多相关文章

  1. hdu 2899 Strange fuction —— 模拟退火

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2899 模拟退火: 怎么也过不了,竟然是忘了写 lst = tmp ... 还是挺容易A的. 代码如下: # ...

  2. hdu 2899 Strange fuction 模拟退火

    求  F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)的最小值 模拟退火,每次根据温度随机下个状态,再根据温度转移 #include& ...

  3. hdu 2899 Strange fuction

    http://acm.hdu.edu.cn/showproblem.php?pid=2899 Strange fuction Time Limit: 2000/1000 MS (Java/Others ...

  4. ACM : HDU 2899 Strange fuction 解题报告 -二分、三分

    Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...

  5. hdu 2899 Strange fuction (二分法)

    Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  6. 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 ( ...

  7. HDU.2899.Strange fuction(牛顿迭代)

    题目链接 \(Description\) 求函数\(F(x)=6\times x^7+8\times x^6+7\times x^3+5\times x^2-y\times x\)在\(x\in \l ...

  8. HDU 2899 Strange fuction 【三分】

    三分可以用来求单峰函数的极值. 首先对一个函数要使用三分时,必须确保该函数在范围内是单峰的. 又因为凸函数必定是单峰的. 证明一个函数是凸函数的方法: 所以就变成证明该函数的一阶导数是否单调递增,或者 ...

  9. HDU 2899 Strange fuction [二分]

    1.题意:给一个函数F(X)的表达式,求其最值,自变量定义域为0到100 2.分析:写出题面函数的导函数的表达式,二分求导函数的零点,对应的就是极值点 3.代码: # include <iost ...

随机推荐

  1. 快乐学习 Ionic Framework+PhoneGap 手册1-3 {面板切换}

    编程的快乐和乐趣,来自于能成功运行程序并运用到项目中,会在后面案例,实际运用到项目当中与数据更新一起说明 从面板切换开始,请看效果图和代码,这只是一个面板切换的效果 Index HTML Code & ...

  2. Guidelines for Successful SoC Verification in OVM/UVM

    By Moataz El-Metwally, Mentor Graphics Cairo Egypt Abstract : With the increasing adoption of OVM/UV ...

  3. Qt开发动画

    #include <QPropertyAnimation> #include <QDesktopWidget> //下坠 void MainWindow::on_pushBut ...

  4. linux输入子系统简述【转】

    本文转载自:http://blog.csdn.net/xubin341719/article/details/7678035 1,linux输入子系统简述 其实驱动这部分大多还是转载别人的,linux ...

  5. JAVA基础补漏--字符串

    字符串常量池 String a="abc"; String b="abc"; char[] str = {"a","b" ...

  6. SYN blood攻击

    SYN Flood (SYN洪水) 是种典型的DoS (Denial of Service,拒绝服务) 攻击.效果就是服务器TCP连接资源耗尽,停止响应正常的TCP连接请求. 说到原理,还得从TCP如 ...

  7. Struts2的Action中访问servletAPI方式

    struts2的数据存放中心为ActionContext,其是每次请求来时都会创建一个ActionContext,访问结束销毁,其绑定在ThreadLocal上,由于每次访问web容器都会为每次请求创 ...

  8. python机器学习——分词

    使用jieba库进行分词 安装jieba就不说了,自行百度! import jieba 将标题分词,并转为list seg_list = list(jieba.cut(result.get(" ...

  9. 基于主主复制的mysql双机热备+keepalived实现高可用性

  10. Spring初学之Spel初配

    Spel又时候可以方便我们为bean的属性赋值,如下配置文件就是常用的一些使用: <?xml version="1.0" encoding="UTF-8" ...