求  F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)的最小值

模拟退火,每次根据温度随机下个状态,再根据温度转移

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<iostream>
  4. #include<algorithm>
  5. #include<cmath>
  6. #define inf (double)0x3f3f3f3f3f3f3f3fll
  7. using namespace std;
  8. double y;
  9. double cal(double x){
  10. return 6*pow(x,7.0)+8*pow(x,6.0)+7*pow(x,3.0)+5*pow(x,2.0)-y*x;
  11. }
  12. double Rand(){
  13. return (rand()%1000)/1000.0;
  14. }
  15. double work(){
  16. double T=100,now=0;
  17. double fnow=cal(now);
  18. double minf=min(inf,fnow);
  19. while(T>0.0000001){
  20. double nxt=now+T*(Rand()*2-1);
  21. if(nxt>=0&&nxt<=100){
  22. double fnxt=cal(nxt);
  23. double dE=fnow-fnxt;
  24. if((dE>0)||(exp(dE/T))>Rand()){
  25. now=nxt;fnow=fnxt;}
  26. }
  27. T*=0.99;
  28. }
  29. return fnow;
  30. }
  31. int main(){
  32. srand(20001101);
  33. int T;
  34. scanf("%d",&T);
  35. while(T--){
  36. scanf("%lf",&y);
  37. printf("%0.4lf\n",work());
  38. }
  39. }

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

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

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2899 还可三分.不过只写了模拟退火. #include<iostream> #include& ...

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

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

  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. python 之路,200行Python代码写了个打飞机游戏!

    早就知道pygame模块,就是没怎么深入研究过,恰逢这周未没约到妹子,只能自己在家玩自己啦,一时兴起,花了几个小时写了个打飞机程序. 很有意思,跟大家分享下. 先看一下项目结构 "" ...

  2. sql server求分组最大值,最小值,最大值对应时间,和最小值对应时间

    先创建数据库 CREATE TABLE [dbo].[Students]( [Id] [int] IDENTITY(1,1) NOT NULL, [age] [int] NULL, [name] [n ...

  3. Eclipse下无法编译,或者WEB-INF/classes目录下没文件,编译失败的解决办法

    1. 确保 project->build automatically 已经被选上. 2. 如果选上了,也不好使, 使用这一招: project->clean..->选第2个clean ...

  4. 分布式文件系统MFS、Ceph、GlusterFS、Lustre的比较

    原文:http://blog.csdn.net/metaxen/article/details/7108958 MooseFS(MFS) Ceph GlusterFS Lustre Metadata ...

  5. iview源码解析(1)

    概述 公司技术栈开始用vue主导开发,但因为公司前端会vue的不多所以在项目中用到vue的技术不是很深,之前出去面试被接连打击,而且本来打算开始为公司vue的项目构建自己的组件库所以去下载了iview ...

  6. Redis案例——商品秒杀,购物车

    秒杀案例: <?php header("content-type:text/html;charset=utf-8"); $redis = new redis(); $resu ...

  7. flex调用JS报安全沙箱错误解决办法

    flex调用JS方法弹窗时一般会报安全沙箱错误,只要将被调用的JS方法设置延时就可解决. function openKqQuery(){ window.showModalDialog("pa ...

  8. arcengine之版本管理

    public void VersionManagement(IVersionedWorkspace versionedWorkspace) { //creating the new version o ...

  9. 关于DataSet中Relations的应用

    using System; using System.Collections.Generic; using System.Text; using System.Data; namespace conn ...

  10. 阿里Java架构师谈谈架构和如何成为一个Java架构师

    架构的定义 我们来看看软件架构的一般定义: 程序和计算系统软件体系结构是指系统的一个或多个结构. 该结构包括软件的构建,构建的外部可见属性以及它们之间的相互关系. 该体系结构不是可操作的软件. 具体来 ...