hdu 2899 Strange fuction——模拟退火
题目: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——模拟退火的更多相关文章
- hdu 2899 Strange fuction —— 模拟退火
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2899 模拟退火: 怎么也过不了,竟然是忘了写 lst = tmp ... 还是挺容易A的. 代码如下: # ...
- hdu 2899 Strange fuction 模拟退火
求 F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)的最小值 模拟退火,每次根据温度随机下个状态,再根据温度转移 #include& ...
- hdu 2899 Strange fuction
http://acm.hdu.edu.cn/showproblem.php?pid=2899 Strange fuction Time Limit: 2000/1000 MS (Java/Others ...
- 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 (二分法)
Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 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(牛顿迭代)
题目链接 \(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 ...
- HDU 2899 Strange fuction 【三分】
三分可以用来求单峰函数的极值. 首先对一个函数要使用三分时,必须确保该函数在范围内是单峰的. 又因为凸函数必定是单峰的. 证明一个函数是凸函数的方法: 所以就变成证明该函数的一阶导数是否单调递增,或者 ...
- HDU 2899 Strange fuction [二分]
1.题意:给一个函数F(X)的表达式,求其最值,自变量定义域为0到100 2.分析:写出题面函数的导函数的表达式,二分求导函数的零点,对应的就是极值点 3.代码: # include <iost ...
随机推荐
- 交叉编译Mesa,X11lib,Qt opengl
记录Mesa配置文件如下: Mesa版本:Mesa-10.2.3 CC=/usr/local/arm-4.8.1/bin/arm-none-linux-gnueabi-gcc CXX=/usr/loc ...
- Linux虚拟内存管理(glibc)
转:https://blog.csdn.net/tengxy_cloud/article/details/53067396 https://www.cnblogs.com/purpleraintear ...
- Java变量修饰符volatile
volatile这个关键字可能很多朋友都听说过,或许也都用过.在Java 5之前,它是一个备受争议的关键字,因为在程序中使用它往往会导致出人意料的结果.在Java 5之后,volatile关键字才得以 ...
- mysql性能优化的一些建议
mysql性能优化的一些建议 1.EXPLAIN 你的 SELECT 查询 查看rows列可以让我们找到潜在的性能问题. 2.为关键字段添加索引,比如:where, order by, group b ...
- web框架详解之三Modal
一.Modal操作之创建表,添加数据 1. 配置Django中settings的设置连接mysql数据库,然后在mysql数据库中创建库 2. 在models中创建表.继承Model 3. 在sett ...
- iOS 学习之 UITabBarController
- (IBAction)btnClick:(id)sender { UITabBarController *tabBarCtrl = [[[UITabBarController alloc] init ...
- 主席树----POJ 2104(主席树裸题)(转)
首先来介绍一下我们需求:给你n个数,多次问你某个区间内的第k小是哪个数 主席树: 主席树的全名应该是 函数式版本的线段树.加上附带的一堆 technology.. ..总之由于原名字太长了,而且 “主 ...
- C# XML对象序列化、反序列化 - PEPE YU
http://www.tuicool.com/articles/IjE7ban http://www.cnblogs.com/johnsmith/archive/2012/12/03/2799795. ...
- hdoj1005--Number Sequence
Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1 ...
- pg数据库表接口和数据导出
导出命令 pg_dump -U postgres --inserts -t human_info > D:\human_info_backup.sql testdb 命令说明 pg_dump:是 ...