0%

CF-1013-(2090)C Dining Hall(小心上界确定问题)

思路讲解

image

这道题目本身不难,但上界的确定没那么好想

AC代码

心路历程(WA,TLE,MLE……)

如果上界是sqrt(N)sqrt(N) 其实桌子是够的,但是不一定能找到最优解。

通过排布规律我们知道他其实是呈三角形排布,所以要变换上界为sqrt(2N)sqrt(2*N)

1
2
3
4
5
6
7
8
9
10
11
12
for(int x=0;x<=sqrtl(2*N);++x){
for(int y=0;y<=sqrtl(2*N);++y){
vis[x][y]=false;
for(int j=0;j<4;++j){
ll fx=3*x+dx[j],fy=3*y+dy[j];
ll dis=genDis(fx,fy,j);
pq.push((arr){fx,fy,x,y,dis});
pq1.push((arr){fx,fy,x,y,dis});
visB[fx][fy]=false;
}
}
}