两点间距离
sqrt( pow( abs(x1-x2) ,2 ) + pow( abs(y1-y2) ) , 2 ) //sqrt()开平方根
//pow(x,y) 得到x的y次方
也可以:sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ) //abs() 得到参数的绝对值
判断质数
// x = a * b -> min(a,b) <=sqrt(x)
int chk(int x){
for(int i = 2;i * i <= x;++i){
if(x % i == 0){
return 0;
}
}
return 1;
}
用数组记录状态
用整数数组标记
eg: int a[n] = {0};
i符合条件: a[i] = 1;
用布尔数组标记
eg: bool a[n];
i符合条件:a[i] = 1;
控制小数输出
cout << fixed << setprecision(1) << res << '\n';


喜欢的话,留下你的评论吧~