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 ...
随机推荐
- win10查看系统启动项,并且禁用
打开任务管理器,有一个叫做start up的选项卡,里面的东西就是启动项. 右键选中需要disable的,然后禁用.
- hdu 1085(普通母函数)
Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- javaBean为什么要implements Serializable
转自:https://www.cnblogs.com/jqlbj/p/6261592.html 一个对象序列化的接口,一个类只有实现了Serializable接口,它的对象才是可序列化的.因此如果要序 ...
- 一个php+jquery+json+ajax实例
json.php <!DOCTYPE html Public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...
- 读入图片显示scipy.misc module has no attribute imread?
>>> import scipy >>> scipy.misc <module 'scipy.misc' from 'C:\Python27\lib\site ...
- OCC 矩阵变换
在OpenCADCADE中, 通过gp_Trsf类来进行矩阵变换操作, 采用矩阵在左的方式: 新点 = 变换矩阵 * 点 基本原理如下: //! Defines a non-persistent tr ...
- 参数转对象 类似 ?camera=1&travel=0&faceScore=1
parseQueryString(url) { var obj = {}; var keyvalue = []; var key = "", value = "" ...
- Walking on the path of Redis --- Introduction and Installation
废话开篇 以前从来没听说过有Redis这么个玩意,无意间看到一位仁兄的博客,才对其有所了解,所以决定对其深入了解下.有不对的地方还请各位指正. Redis介绍 下面是官方的介绍,不喜欢english的 ...
- 安装typescript开发环境
参考文档: http://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html 有两个方式 : 1.安装vs 2017,安 ...
- Docker镜像的备份和恢复
备份: docker save -o [tar包真实路径] [镜像名 ] 如:docker save -o /usr/docker_data/mongo-backup.tar mongo 导出: ...