专栏文章

11.9模拟训练

个人记录参与者 1已保存评论 0

文章操作

快速查看文章及其快照的属性,并进行相关操作。

当前评论
0 条
当前快照
1 份
快照标识符
@miqw4hyu
此快照首次捕获于
2025/12/04 11:42
3 个月前
此快照最后确认于
2025/12/04 11:42
3 个月前
查看原文
T1
根据题意简单模拟即可,注意循环范围为2~s.length()-2
Code:
CPP
#include<iostream>
#include<string>
using namespace std;
int n,ans;
string s;
int main(){
    cin>>n>>s;
    for(int i=0;i<n-2;i++){
    	if(s[i]=='#' && s[i+1]=='.' && s[i+2]=='#') ans++;
	}
	cout<<ans;
    return 0;
}
T2
同样根据题意模拟,注意以下几点:
1.从(0,0)开始,还要回到(0,0)
2.输入要开long long,否则可能导致在计算过程中爆int,再sqrt就会变成无限小(nan)
Code:
CPP
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
long long t,x,y,xx,yy;
double ans;
int main(){
	cin>>t;
	t--;
	cin>>x>>y;
	ans+=sqrt((0-x)*(0-x)+(0-y)*(0-y));
	xx=x;
	yy=y;
	while(t--){
		cin>>x>>y;
		ans+=sqrt((xx-x)*(xx-x)+(yy-y)*(yy-y));
		xx=x;
		yy=y;
	}
	ans+=sqrt((xx-0)*(xx-0)+(yy-0)*(yy-0));
	cout<<fixed<<setprecision(10)<<ans;
    return 0;
}

评论

0 条评论,欢迎与作者交流。

正在加载评论...