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 ...
随机推荐
- luogu2431 正妹吃月饼
题目大意 求一个正整数集合\(K\),使得\(\sum_{k\in K}2^k\in[A,B]\),且\(|K|\)最大.\(A,B\)大小在long long范围内. 思路 \(\sum_{k\in ...
- js设计模式-工厂模式(抽象工厂)
场景:定义一个抽象类 AbsProducer(生产商),该生产商有两个行为,一个生产,一个出售,其中生产方法为抽象方法,由具体的厂家(工厂)去实现,出售的产品均是电子产品(返回的对象为电子产品对象,即 ...
- 从默认析构函数学习c++,new,delete,内存泄漏,野指针
默认析构函数:当系统没有显式定义析构函数,编译器同样会为对象定义一个默认析构函数,默认的析构函数只能释放普通数据成员所占用的空间,无法通过释放通过new和malloc进行申请的空间,因此避免内存泄漏, ...
- 浅析CLR的异常处理模型
文章目录: 异常概述 CLR中的异常处理机制 CLR中异常的核心类System.Exception类 异常处理的设计规范和最佳实践 异常处理的性能问题 其他拓展 1.异常概述 异常我们通常指的是行动成 ...
- ADODB.RecordSet常用方法查询
rs = Server.CreateObject("ADODB.RecordSet") rs.Open(sqlStr,conn,1,A) 注:A=1表示读取数据:A=3表示新增.修 ...
- Android RecyclerView、ListView实现单选列表的优雅之路.
一 概述: 这篇文章需求来源还是比较简单的,但做的优雅仍有值得挖掘的地方. 需求来源:一个类似饿了么这种电商优惠券的选择界面: 其实就是 一个普通的列表,实现了单选功能, 效果如图: (不要怪图渣了 ...
- RN打包的那些坑儿
Write By lz: Lz 寄语: RN虐我千百遍, 我待RN如初恋, 坑儿爬多了也就自然了 官方文档: http://reactnative.cn/docs/0.43/signed-apk-an ...
- wp版笔记本应用源码
今天在那个WP教程网看到了一个不错的项目,简单的记事本,主要是用到的独立存储文件的操作,TimePicker和DatePicker的是用,数据绑定,界面的参考的chanraycode的,主要是锻炼自己 ...
- OpenStack、KVM、Docker——Docker之后还需要OpenStack吗?
原文链接:http://news.csdn.net/article_preview.html?preview=1&reload=1&arcid=2823129 Docker从一个新兴的 ...
- 使用序列号激活优动漫PAINT(附激活码)
优动漫PAINT是一款功能强大的动漫绘图软件,简单的中文界面和丰富的笔刷操纵,再次为设计工作者带来非一般的感受!最近,有不少小伙伴提出这样的疑问:购买安装优动漫PAINT之后,不知道如何激活,在哪里输 ...