A

按照题意模拟就行,时间复杂度 O(N)O(N)

#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) 求解 x2+y2\sqrt{x^2+y^2}

该函数在 C++、python 中都有,其中 C++ 需要头文件 <cmath,该函数在 C++11 版本中正式被引入,在 C++17 版本中添加了三个参数的版本。

绝对误差:你的回答标准答案106|\text{你的回答} - \text{标准答案}| \leq 10^{-6}

需要注意:最后要回到原点

#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); 
}

C

D