zoukankan      html  css  js  c++  java
  • 2015弱校联盟(1) -A. Easy Math

    A. Easy Math
    Time Limit: 2000ms
    Memory Limit: 65536KB

    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
    判断每一个数是不是平方数,如果不是平方数,最后的结果不是整数

    #include <bits/stdc++.h>
    #define LL long long
    #define fread() freopen("in.in","r",stdin)
    #define fwrite() freopen("out.out","w",stdout)
    
    using namespace std;
    
    
    int main()
    {
        int n,data;
        while(~scanf("%d",&n))
        {
            bool flag=false;
            while(n--)
            {
                scanf("%d",&data);
                if(flag)
                {
                    continue;
                }
                int ans=(int)sqrt(data);
                if(ans*ans!=data)//判断是不是平方数
                {
                    flag=true;
                }
            }
            if(flag)
            {
                cout<<"No"<<endl;
            }
            else
            {
                cout<<"Yes"<<endl;
            }
        }
        return 0;
    }
    
  • 相关阅读:
    jsp输出当前时间
    java连接操作Oracle
    Oracle 内置函数
    伪表和伪列
    关于listview视图的 作业
    5月21日 课堂总结
    网格布局作业
    网格布局视图整理
    5月19日课堂总结
    拷贝程序
  • 原文地址:https://www.cnblogs.com/juechen/p/5255913.html
Copyright © 2011-2022 走看看