@[树链剖分](/space/show?uid=124721) 那是铁的颜色变化……
by 硫酸钒酰 @ 2018-11-05 20:49:15
$O_2$负优化很正常...
by AutumnKite @ 2018-11-05 20:49:31
@[Max雷](/space/show?uid=84986) 我知道,无聊玩个梗
by Ynoi @ 2018-11-05 20:54:37
@[rill7747](/space/show?uid=20561) 不至于AC->全TLE 吧
by Ynoi @ 2018-11-05 20:58:00
怕都是极限数据吧...
by AutumnKite @ 2018-11-06 07:32:35
~~或者你代码的常数比较优秀~~
by AutumnKite @ 2018-11-06 07:33:01
```
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
#define MAXN 15
#define db double
#define INF 0x3f3f3f3f
int n,m;
int a[MAXN][4];
int c[MAXN];
int rp = INF;
void rd()
{
scanf("%d",&n);
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= 3; j ++)
scanf("%d",&a[i][j]);
}
db sj() {
return ((db)(rand()*rand()%19260817))/(db)19260817;
}
int suan()
{
int ans = 0;
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= 3; j ++)
ans += abs(c[i] - c[a[i][j]]);
rp = min(rp,ans>>1);
return (ans>>1);
}
db mnth(db t,db dt,db tt)
{
int an = 0;
for(;t >= tt; t = t*dt)
{
int x = rand()%n+1,y = rand()%n+1;
int ls = suan();
swap(c[x],c[y]);
int ans = suan();
//for(int i = 1; i <= n; i ++)
// cout<<c[i]<<" ";
//cout<<"\n";
if(ans < ls || exp((ans - ls)/t) < sj()*10)
;
else
swap(c[x],c[y]);
}
for(int i = 1; i <= 2333; i ++)
{
int x = rand()%n+1,y = rand()%n+1;
int ls = suan();
swap(c[x],c[y]);
int ans = suan();
if(ans < ls)
;
else
swap(c[x],c[y]);
}
}
int main()
{
srand(19260817);
rd();
for(int i = 1; i <= n; i ++)
c[i] = i;
for(int i = 1; i <= 4; i ++)
mnth(10000000,0.9997,0.00000001);
cout<<rp;
return 0;
}
/*
6
6 2 5
1 3 4
4 2 6
5 3 2
4 6 1
1 5 3
*/
```
by Ynoi @ 2018-11-06 08:02:07
这是模拟退火吗……
by Seauy @ 2018-11-30 16:58:39