水题赛题解
lyhr31415926
·
·
个人记录
$T4$ 是一道线段树板子题,把这道题放上去是这次比赛在出题方面的最大失误,导致不会此算法的人做不出来。但暴力非常好打,学了数组就应该会做,期望得分 $60$。
线段树就不讲了,这个内容比较困难,你们自己去看吧。
$T5$ 也特别水,数组都不用,就是 $A+B Problem$ 的拓展版,随便写写就过了。
$T6$ 暴力也是给了 $60$,直接 $A * BProblem$ 就完了,记得每一步都要取模。
正解是快速幂(也是模板),需要用到位运算的思想,也不讲了。
$T7$ 应该是最难题,用到了搜索,还有大量的卡常,时间卡得很紧,基本慢个 $2-4ms$ 就没了,必须把剪枝运用的极致,这里直接放上 $std$ 的满分代码,大家自己对照:
```cpp
#include<bits/stdc++.h>
using namespace std;
int n;
double x[100], y[100], ans=1e9, sum;
bool b[100];
double min(double x, double y) {
if(x < y) return x;
return y;
}
double calc(int X, int Y) {
return sqrt((x[X]-x[Y])*(x[X]-x[Y])+(y[X]-y[Y])*(y[X]-y[Y]));
}
void dfs(int step, int pre) {
if(sum >= ans) return;
if(step == n + 1) {
ans = min(ans, sum);
return;
}
for(int i = 1; i <= n; ++i) {
if(b[i]) continue;
b[i] = 1;
sum += calc(pre, i);
dfs(step + 1, i);
b[i] = 0;
sum -= calc(pre, i);
}
return;
}
int main() {
scanf("%d",&n);
if(n == 1) {
printf("%.2lf",0);
return 0;
}
for(int i = 1; i <= n; ++i) {
scanf("%lf%lf",&x[i],&y[i]);
}
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j) b[j] = 0;
sum = 0;
b[i] = 1;
dfs(2, i);
b[i] = 0;
}
printf("%.2lf",ans);
return 0;
}
```
所以,以刚学过数组的水平来说,至少应该获得 $100+100+100+60+100+60+0=520$ 分的,但大家的分数似乎都不太理想。。。$520$ 分以上的只有一个外校的大佬,而其他人连暴力都不会。。。
@ [3lb_dl3](https://www.luogu.com.cn/user/926776) 表现还是不错的,只可惜 $T3$ 想的有些复杂,其实不用排序,只需找到最大值就行了。