SCU 4436 Easy Math 2015年四川省赛题

题目链接:http://acm.scu.edu.cn/soj/problem/4436/

题意:给你n个整数,求这n个数的平方根和是否是一个整数;

解题思路:如果这题每个数给他算出来,必然费时间,可能还会超精度,所以巧妙的方法就是判断这些整数是否全是完全平方数,如果有一个不是,则他们的平方根和肯定不是一个整数。

AC代码:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
int is(int x)
{
  int y=sqrt(x);
  if(y*y==x) return 0;
  return 1;
}
int main()
{
 int n;
 while(scanf("%d",&n)!=EOF)
 {
  int f=1;
  for(int i=0;i<n;i++)
  {
   int x;
   scanf("%d",&x);
   if(is(x)) f=0;
  }
  if(f) puts("Yes");
  else  puts("No");
 }
 return 0;
}
原文地址:https://www.cnblogs.com/www-cnxcy-com/p/5738279.html