[题目链接] (http://www.bnuoj.com/v3/contest_show.php?cid=6865#problem/0)
题目描述:
A. Easy Math
Time Limit: 2000msMemory Limit: 65536KB 64-bit integer IO format: %lld Java class name: Main
Submit Status
Given n integers a1,a2,…,an, check if the sum of their square root a1−−√+a2−−√+⋯+an−−√ is a integer.
Input
The input consists of multiple tests. For each test:
The first line contains 1 integer n (1≤n≤105).
The second line contains n integers a1,a2,…,an (0≤ai≤109).
Output
For each test, write ‘‘Yes′′ if the sum is a integer, or ‘‘No′′ otherwise.
Sample Input
2
1 4
2
2 3
Sample Output
Yes
No
言简意赅:
此题是要求n个数的平方根的和是否为一个整数,直接计算求解即可,不需要有太多的其他方面的顾虑,水题~
代码实现如下:
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int a[100010];
int main()
{
int n;
double sum;
while(scanf("%d",&n)!=EOF)
{
sum=0;
for(int i=0; i<n; i++)
{
scanf("%d",&a[i]);
sum+=(double)sqrt(a[i]);//此处一定要加上类型转换成double,否则数据在存储时会出现错误
}
//cout<<"sum="<<(long long)sum<<endl;
if(sum==(long long)sum)
{
printf("Yes\n");
}
else printf("No\n");
}
return 0;
}
本文介绍如何解决一个简单的数学问题,即判断一组整数的平方根之和是否为整数。通过直接计算求解,本题被归类为水题。代码实现展示了输入数据的处理过程,包括读取测试用例数量、每个测试用例的整数数组以及最终输出结果。此题旨在锻炼基础的数学和编程能力。

3945

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



