题意翻译

给定一组有n个整数的数组a1,a2,…,an.找出这组数中的最大非完全平方数。 完全平方数是指有这样的一个数x,存在整数y,使得x=y^2y2 .

输入格式

第一行输入一个单独的整数n(1<=n<=1000 ),n为该组数的数量。 接下来有n个整数,a1,a2,an(-10^6<=a<=10^6) 数据保证至少存在一个整数是非完全平方数。

题目描述

Given an array a_{1},a_{2},...,a_{n}a1​,a2​,...,an​ of nn integers, find the largest number in the array that is not a perfect square.

A number xx is said to be a perfect square if there exists an integer yy such that x=y^{2}x=y2 .

输入输出格式

输入格式:

The first line contains a single integer nn ( 1<=n<=10001<=n<=1000 ) — the number of elements in the array.

The second line contains nn integers a_{1},a_{2},...,a_{n}a1​,a2​,...,an​ ( -10^{6}<=a_{i}<=10^{6}−106<=ai​<=106 ) — the elements of the array.

It is guaranteed that at least one element of the array is not a perfect square.

输出格式:

Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists.

输入输出样例

输入样例#1: 复制

2
4 2
输出样例#1: 复制

2
输入样例#2: 复制

8
1 2 4 8 16 32 64 576
输出样例#2: 复制

32

说明

In the first sample case, 44 is a perfect square, so the largest number in the array that is not a perfect square is 22 .

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 1001
using namespace std;
int n;
int num[MAXN];
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&num[i]);
sort(num+,num++n);
for(int i=n;i>=;i--){
int k=sqrt(num[i]);
if(k*k!=num[i]){
cout<<num[i];
return ;
}
}
}

CF914A Perfect Squares的更多相关文章

  1. [LintCode] Perfect Squares 完全平方数

    Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...

  2. LeetCode Perfect Squares

    原题链接在这里:https://leetcode.com/problems/perfect-squares/ 题目: Given a positive integer n, find the leas ...

  3. Perfect Squares

    Perfect Squares Total Accepted: 18854 Total Submissions: 63048 Difficulty: Medium Given a positive i ...

  4. Light OJ 1288 Subsets Forming Perfect Squares 高斯消元求矩阵的秩

    题目来源:Light OJ 1288 Subsets Forming Perfect Squares 题意:给你n个数 选出一些数 他们的乘积是全然平方数 求有多少种方案 思路:每一个数分解因子 每隔 ...

  5. [LeetCode] 0279. Perfect Squares 完全平方数

    题目 Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9 ...

  6. LeetCode 279. 完全平方数(Perfect Squares) 7

    279. 完全平方数 279. Perfect Squares 题目描述 给定正整数 n,找到若干个完全平方数(比如 1, 4, 9, 16, ...)使得它们的和等于 n.你需要让组成和的完全平方数 ...

  7. Leetcode之广度优先搜索(BFS)专题-279. 完全平方数(Perfect Squares)

    Leetcode之广度优先搜索(BFS)专题-279. 完全平方数(Perfect Squares) BFS入门详解:Leetcode之广度优先搜索(BFS)专题-429. N叉树的层序遍历(N-ar ...

  8. 花式求解 LeetCode 279题-Perfect Squares

    原文地址 https://www.jianshu.com/p/2925f4d7511b 迫于就业的压力,不得不先放下 iOS 开发的学习,开始走上漫漫刷题路. 今天我想聊聊 LeetCode 上的第2 ...

  9. [LeetCode] Perfect Squares 完全平方数

    Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...

随机推荐

  1. NEU操作系统实验课4——线程同步

    实验要求: 创建两个线程按数字顺序打印10以下自然数,其中一个线程打印1-3及8-10:另一个线程打印4-6.要求使用线程同步机制实现上述打印顺序. 看网上的资料学习了两种写法 C++11的,使用了s ...

  2. 杂项-地图:LBS

    ylbtech-杂项-地图:LBS 基于位置的服务,它是通过电信移动运营商的无线电通讯网络(如GSM网.CDMA网)或外部定位方式(如GPS)获取移动终端用户的位置信息(地理坐标,或大地坐标),在地理 ...

  3. 搭建自己的websocket server_1

    用Node.js实现一个WebSocket的Server. https://github.com/sitegui/nodejs-websocket#event-errorerr   nodejs-we ...

  4. kafka+storm 单机运行

    环境: 1.kafka+zookeeper 2.window平台 3.eclipse 设置: 1.kafka和zookeeper安装,另一篇有介绍(https://www.cnblogs.com/51 ...

  5. python的模块导入

    单个文件导入:导入的模块可以是一个py文件(放置在当前文件的同级目录.默认路径等) 导入:import 模块名 使用:模块名.函数名 导入:from 模块名 import * 使用:函数名 ----- ...

  6. Hadoop MapReduce编程 API入门系列之分区和合并(十四)

    不多说,直接上代码. 代码 package zhouls.bigdata.myMapReduce.Star; import java.io.IOException; import org.apache ...

  7. ES6变量的解构赋值

    变量的解构赋值 1.数组的解构赋值 2.对象的解构赋值 3.字符串的解构赋值 4.数值和布尔值的解构赋值 5.函数参数的解构赋值 6.圆括号问题 7.用途 1.数组的解构赋值 ES6 允许写成下面这样 ...

  8. Spring AOP理解

    Spring的核心思想的IOC和AOP.最近学习AOP,对切面的学习有了进一步的认识. Spring用代理类包裹切面,把他们织入到Spring管理的bean中.也就是说代理类伪装成目标类,它会截取对目 ...

  9. aspnet_regiis加密文件提示路径中具有非法字符

    加密结果受当前目录影响,不知道是不是哪里操作错误,mark.   Web.config文件位置:E:\Web\Surgery 加密成功,上图命令最后有个".",表示web.conf ...

  10. Win8.1应用开发之适配器模式(C#实现)

    实际上适配器模式是用于解耦.设想一下我们的程序模块A在与模块B打交道时,需要在许多地方多次使用B中某个类的方法,而负责开发B的程序猿Tom还未完全实现该类,会随时更改该类中的方法,那么当Tom在修改时 ...