CF914A Perfect Squares
题意翻译
给定一组有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.
输入输出样例
说明
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的更多相关文章
- [LintCode] Perfect Squares 完全平方数
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...
- LeetCode Perfect Squares
原题链接在这里:https://leetcode.com/problems/perfect-squares/ 题目: Given a positive integer n, find the leas ...
- Perfect Squares
Perfect Squares Total Accepted: 18854 Total Submissions: 63048 Difficulty: Medium Given a positive i ...
- Light OJ 1288 Subsets Forming Perfect Squares 高斯消元求矩阵的秩
题目来源:Light OJ 1288 Subsets Forming Perfect Squares 题意:给你n个数 选出一些数 他们的乘积是全然平方数 求有多少种方案 思路:每一个数分解因子 每隔 ...
- [LeetCode] 0279. Perfect Squares 完全平方数
题目 Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9 ...
- LeetCode 279. 完全平方数(Perfect Squares) 7
279. 完全平方数 279. Perfect Squares 题目描述 给定正整数 n,找到若干个完全平方数(比如 1, 4, 9, 16, ...)使得它们的和等于 n.你需要让组成和的完全平方数 ...
- Leetcode之广度优先搜索(BFS)专题-279. 完全平方数(Perfect Squares)
Leetcode之广度优先搜索(BFS)专题-279. 完全平方数(Perfect Squares) BFS入门详解:Leetcode之广度优先搜索(BFS)专题-429. N叉树的层序遍历(N-ar ...
- 花式求解 LeetCode 279题-Perfect Squares
原文地址 https://www.jianshu.com/p/2925f4d7511b 迫于就业的压力,不得不先放下 iOS 开发的学习,开始走上漫漫刷题路. 今天我想聊聊 LeetCode 上的第2 ...
- [LeetCode] Perfect Squares 完全平方数
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...
随机推荐
- Qt的Socket数据通讯的一个样例。
QTcpServer类 用来侦听port ,获取QTcpSocket. QTcpSocket有 connected的信号(已经连接),还有readyread()信号,表示已经有数据发过来了.准备读取 ...
- 编程算法 - 数组中的逆序对 代码(C)
数组中的逆序对 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 在数组中的两个数字假设前面一个数字大于后面的数字, 则这两个数字组成一个逆序对. ...
- Linux用户和组的管理
一.概述: 1.Linux下的三类用户: (1).超级用户(root)具有操作系统的一切权限UID值均为0 (2).普通用户具有操作系统有限的权限UID值500~6000 (3).伪用户是为了方便系统 ...
- android 添加新的键值,自定义按键【转】
本文转载自:http://blog.csdn.net/mr_raptor/article/details/8053871 在Android中,上层可使用的键值默认情况下是92个,从0-91:一般情况下 ...
- POJ 1200 Hash
我的hash从来没写对过........ (白学了快一年OI --原来连个hash都没写对过) 但是 但是 今天是一个值得纪念的日子. 看看标题 我竟然在写hash的题解. (好了好了 废话少说) 题 ...
- window下安装svn
下载 http://subversion.apache.org/ 注意:上边的黑窗口不要关闭! 如何校验svn服务有运行
- 原生js实现简单JSONP
JSONP是一种非常常见的实现跨域请求的方法.其基本思想是利用浏览器中可以跨域请求外链的JS文件,利用这一特性实现数据传输. 用原生JS实现JSONP非常简单,无非几点: 1)定义一个函数,用于处理接 ...
- Android入门知识
1.Android开发环境 Android常用的开发环境包括两个:Eclipse + ADT 和Android Studio,Android Studio作为google官方推出的开发环境自然有得天独 ...
- DataGridView属性设置汇总
1.标题列居中 外观 ColumnHeadersDefaultCellStyle - Alignment - MiddleCenter 2.表格内容居中 外观 DefaultCellStyle - ...
- Nagios Windows客户端NSClient++ 0.4.x安装配置
NSClient++ 0.3.x和NSClient++ 0.4.x的配置完全不一样,官方的文档也没有全部更新.我记录下自己的一些操作. 一.下载安装NSClient++ 1.到http://nsc ...