Switch Game
像这种题一般的蛮力法是会超时的,只能通过打印一部分结果然后找规律再确定怎么写程序。
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int m;
while(cin>>m){
int temp = (int)sqrt(double(m));
temp *= temp;
if(temp == m){
cout<<1<<endl;
}else{
cout<<0<<endl;
}
}
system("pause");
}
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int m;
while(cin>>m){
int temp = (int)sqrt(double(m));
temp *= temp;
if(temp == m){
cout<<1<<endl;
}else{
cout<<0<<endl;
}
}
system("pause");
}
本文介绍了一种快速判断一个整数是否为完全平方数的方法。通过使用C++编程语言中的sqrt函数进行取整运算,该算法能够高效地解决此问题。
8924

被折叠的 条评论
为什么被折叠?



