//Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and 
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
// same ids are connected.
// prefix 的格式要求是 acm-[一级标题编号].[二级标题编号][该代码片段的英文简称]
// description 的格式要求是 "插入 [该代码片段的中文名]"

{
    "模拟退火  (均分数据)": {
        "prefix": "acm-1.5序列随机swap",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#include<cmath>",
            "#define LD double",
            "#define LL long long",
            "#define Re register int",
            "using namespace std;",
            "const int N=23;",
            "int n,m,S,A[N];LD x0;",
            "inline void in(Re &x){",
            "    int f=0;x=0;char c=getchar();",
            "    while(c<'0'||c>'9')f|=c=='-',c=getchar();",
            "    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();",
            "    x=f?-x:x;",
            "}",
            "inline void Srand(Re seed){",
            "\tsrand(seed);Re a=rand()%10+1;",
            "\twhile(a--)srand(rand());",
            "}",
            "inline void Random(Re *A,Re n){",
            "\tfor(Re i=1;i<=n;++i)swap(A[i],A[rand()%n+1]);",
            "}",
            "int x[N];",
            "inline LD calc(Re *A){",
            "\tfor(Re i=1;i<=m;++i)x[i]=0;",
            "\tfor(Re i=1;i<=n;++i){",
            "\t\tRe w=1;",
            "\t\tfor(Re j=2;j<=m;++j)if(x[j]<x[w])w=j;",
            "\t\tx[w]+=A[i];",
            "\t}",
            "\tLD tmp=0;",
            "\tfor(Re i=1;i<=m;++i)tmp+=(x[i]-x0)*(x[i]-x0);",
            "\treturn tmp/m;",
            "}",
            "int nowA[N],ansA[N];LD ans;",
            "const LD deltaT=0.995,maxT=4995,minT=1e-15;",
            "inline void fire(){",
            "\tfor(Re i=1;i<=n;++i)nowA[i]=ansA[i];LD nowT=maxT;",
            "\twhile(nowT>minT){",
            "\t\tRe x=rand()%n+1,y=rand()%n+1;",
            "\t\tswap(nowA[x],nowA[y]);",
            "\t\tLD nans=calc(nowA),deltaE=nans-ans;",
            "\t\tif(deltaE<0){for(Re i=1;i<=n;++i)ansA[i]=nowA[i];ans=nans;}",
            "\t\telse if(exp(-deltaE/nowT)>(LD)rand()/RAND_MAX);",
            "\t\telse swap(nowA[x],nowA[y]);",
            "\t\tnowT*=deltaT;",
            "\t}",
            "}",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tin(n),in(m);",
            "\tfor(Re i=1;i<=n;++i)in(A[i]),S+=A[i];x0=(LD)S/m;",
            "\tfor(Re i=1;i<=n;++i)ansA[i]=A[i];",
            "\tSrand(965579261),Random(ansA,n),Srand(20030825);",
            "\tans=calc(ansA),fire(),fire(),fire(),fire(),fire();",
            "\tprintf(\"%.2lf\\n\",sqrt(ans));",
            "}",
            ""
        ],
        "description": "插入 模拟退火  (均分数据)"
    }
}