- MysGln 的博客
[Engeeker周赛 Div1] 20241115题解
- @ 2024-11-22 15:22:47
A
按照题意模拟就行,时间复杂度 。
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int ans = 0;
for (int i = 0; i < n - 2; i++)
if (s[i] == '#' && s[i + 1] == '.' && s[i + 2] == '#') ans++;
cout << ans << '\n';
}
B
按照题意进行模拟,可以使用 sqrt 函数求平方根,也可以使用 hypot(x,y) 求解 。
该函数在 C++、python 中都有,其中 C++ 需要头文件 <cmath,该函数在 C++11 版本中正式被引入,在 C++17 版本中添加了三个参数的版本。
绝对误差:
需要注意:最后要回到原点。
#include<cstdio>
#include<cmath>
int main(){
int n;
scanf("%d", &n);
double ans = 0;
int crrx = 0;
int crry = 0;
for(int i=0; i<n; i++){
int x, y;
scanf("%d%d", &x, &y);
ans += hypot(x-crrx, y-crry);
crrx = x;
crry = y;
}
ans += hypot(crrx, crry);
printf("%.10f\n", ans);
}