zoukankan      html  css  js  c++  java
  • 备战NOIP——模板复习8

    这里只有模板,并不作讲解,仅为路过的各位做一个参考以及用做自己复习的资料,转载注明出处。

    模拟退火(SA)

    /*Copyright: Copyright (c) 2018
    *Created on 2018-10-28  
    *Author: 十甫
    *Version 1.0 
    *Title: SA
    *Time: 5 mins
    */
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstdlib>
    #include<ctime>
    using namespace std;
    const double delta = 0.999;
    const double zero = 1e-3;
    const double eps = 1e-7;
    
    double calc(double k) {
    }
    
    int main() {
    	srand(time(NULL));
    	int n;
    	scanf("%d", &n);
    	while(n--) {
    		//scanf()
    		double T = 1000.0;
    		double ans = 0.0, x = 0.0;
    		while(T > zero) {
    			double x_ = x + ((rand() * 2) - RAND_MAX) * T;
    			double k = calc(x_) - ans;
    			if(k > 0) {
    				ans = k, x = x_;
    			} else {
    				if(exp(-k / T) * RAND_MAX > rand()) {
    					x = x_;
    				}
    			}
    			T *= delta;
    		}
    		printf("%.5lf
    ", ans);
    	}
    	return 0;
    }
    NOIP 2018 RP++
  • 相关阅读:
    Java 继承和重写
    Java 构造函数和函数重载
    java 面向对象
    for循环和数组例题
    java数组和函数
    java程序流程控制
    CF600C Make Palindrome
    CF600A Extract Numbers
    [NOI2007]社交网络
    SPOJ 6779 GSS7
  • 原文地址:https://www.cnblogs.com/Black-S/p/9886213.html
Copyright © 2011-2022 走看看