HDU 2899Strange fuction(模拟退火)
题意
求 $F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)$的最小值
Sol
强上模拟退火,注意eps要开大!
/*
*/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
using namespace std;
const int MAXN = 1e6 + ;
const double eps = 1e-, Dlt = 0.98;
int T;
double Y, Best;
double F(double x) {
return * x * x * x * x * x * x * x + * x * x * x * x * x * x + * x * x * x + * x * x - Y * x;
}
double getrand(double T) {
return T * ((rand() << ) - RAND_MAX);
}
double solve(int id) {
double x = id, now = F(x);
Best = min(Best, now);
for(double T = ; T > eps; T *= Dlt) {
double wx = x + getrand(T), wv = F(wx);
if(wx > eps && (wx - <= eps)) {
if(wv < Best) x = wx, Best = wv, now = wv;
if(wv < now || ((exp((wv - now) / T)) * RAND_MAX < rand())) now = wv, x = wx;
}
}
}
int main() {
srand((unsigned)time(NULL));
scanf("%d", &T);
while(T--) { Best = 1e20;
scanf("%lf", &Y);
int times = ;
while(times--) solve(times);
printf("%.4lf\n", Best);
}
return ;
}
/*
3
100
200
1000000000
*/
HDU 2899Strange fuction(模拟退火)的更多相关文章
- 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的. 代码如下: # ...
- 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 5017 Ellipsoid 模拟退火第一题
为了补这题,特意学了下模拟退火算法,感觉算法本身不是很难,就是可能降温系数,步长等参数不好设置. 具体学习可以参见: http://www.cnblogs.com/heaad/archive/2010 ...
- Groundhog Build Home - HDU - 3932(模拟退火)
题意 给定一个矩形内的\(n\)个点,在矩形中找一个点,离其他点的最大距离最小. 题解 模拟退火. 这个题需要\(x\)和\(y\)坐标随机动的时候多随机几次.否则就WA了.另外由于随机多次,如果温度 ...
- The Moving Points - HDU - 4717 (模拟退火)
题意 二维空间中有\(n\)个运动的点,每个点有一个初始坐标和速度向量.求出一个时间\(T\),使得此时任意两点之间的最大距离最小.输出\(T\)和最大距离. 题解 模拟退火. 这个题告诉了我,初始步 ...
- hdu Strange fuction
本题是一道二分题,但是要利用导数来求最小值.对原函数进行求导,得到的导函数为f(x)=42*pow(x,6)+48*pow(x,5)+21*pow(x,2)+10*x-y;因为0<=x<= ...
- HDU - 5017 Ellipsoid(模拟退火法)
Problem Description Given a 3-dimension ellipsoid(椭球面) your task is to find the minimal distance bet ...
- hdu 2899 Strange fuction
http://acm.hdu.edu.cn/showproblem.php?pid=2899 Strange fuction Time Limit: 2000/1000 MS (Java/Others ...
随机推荐
- AtCoder Grand Contest 028 A:Two Abbreviations
题目传送门:https://agc028.contest.atcoder.jp/tasks/agc028_a 题目翻译 给你两个串\(s\)与\(t\),长度分别为\(n,m\).问你存不存在一个串长 ...
- Out of resources when opening file ‘./xxx.MYD’ (Errcode: 24)解决方法
今天朋友向我反映网站出现错误:Out of resources when opening file './xxx.MYD' (Errcode: 24)错误是因为打开的文件数超过了my.cnf的--op ...
- ubuntu下 修改主机名
sudo gedit /etc/hostname 写入: sudo gedit /etc/hosts
- Hadoop——hive安装
安装前先确保安装好MySQL,具体见hadoop_MySQL安装 1.下载hive(下载前先去spark官网看下sparkSQL支持到哪个版本的hive,本文hive版本为1.2.1) 2.解压到/u ...
- bzoj5093
NTT+组合数学 $把每个点分别按度数考虑,由于有标号,可以得出$ $ans=n*2^{(n-1)*(n-2)}*\sum_{i=1}^{n-1}{C(n-1,i)*i^{k}}$ $本质上是求\su ...
- python3-----反射实例
#/usr/bin/env python # -*- coding:utf-8 -*- import sys,os class WebServer(object): def __init__(self ...
- [poj2019]Cornfields(二维RMQ)
题意:给你一个n*n的矩阵,让你从中圈定一个小矩阵,其大小为b*b,有q个询问,每次询问告诉你小矩阵的左上角,求小矩阵内的最大值和最小值的差. 解题关键:二维st表模板题. 预处理复杂度:$O({n^ ...
- MFC编辑框数据实时更新问题
在VC里,很多情况下需要更新控件,也就是调用UpdateData(FALSE);但是如果是在循环中调用该函数,会导致没有时间来刷新界面,消息得不到相应,从外部看来,似乎整个循环只执行了一次Update ...
- prototype for '类名::函数名'does not match any in class'类名'
函数声明和定义参数类型必须相同. 前置声明一定要放到名称空间内,代表该名称空间内的类.
- 将Opencv java中的Mat通过jni传递到C++中的方法
public native void FindFeatures(long matAddrGr, long matAddrRgba); ... mRgba = new Mat(height, width ...