CodeForces 299A Ksusha and Array
http://codeforces.com/problemset/problem/299/A
题意 :输入n个数,要求找出一个数能让其他所有的数整除,如果没有的话输出-1.有多个的话输出其中一个。
思路 :表示一开始看错题了,卡了好久,后来想了想就去翻译了一下,才懂什么意思。。。-.-||。。其实就是要找的话如果有这样一个数就一定是最小的那个数,所以只需要判断一下最小的那个数能不能被后边的数整除就可以了。
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std ;
int a[] ;
int main()
{
int n ;
while(cin>>n)
{
scanf("%d",&a[]) ;
//int minn = a[0] ;
for(int i = ; i < n ; i++)
{
scanf("%d",&a[i]) ;
//minn = min(minn,a[i]) ;
}
sort(a,a+n) ;
int flag = ;
for(int i = ; i < n ; i++)
{
if(a[i] % a[] != )
{
flag = ;
break ;
}
// cout<<a[i]<<endl ;
}
if(flag)
printf("%d\n",a[]) ;
else printf("-1\n") ;
}
return ;
}
CodeForces 299A Ksusha and Array的更多相关文章
- Codeforces 442C Artem and Array(stack+贪婪)
题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数.删除一个数的得分为两边数的最小值,假设左右有一边不存在则算作0分. 问最大得分是多少. ...
- Codeforces Round #504 D. Array Restoration
Codeforces Round #504 D. Array Restoration 题目描述:有一个长度为\(n\)的序列\(a\),有\(q\)次操作,第\(i\)次选择一个区间,将区间里的数全部 ...
- Educational Codeforces Round 21 D.Array Division(二分)
D. Array Division time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- Codeforces 754A Lesha and array splitting(简单贪心)
A. Lesha and array splitting time limit per test:2 seconds memory limit per test:256 megabytes input ...
- Codeforces 408 E. Curious Array
$ >Codeforces \space 408 E. Curious Array<$ 题目大意 : 有一个长度为 \(n\) 的序列 \(a\) ,\(m\) 次操作,每一次操作给出 \ ...
- Educational Codeforces Round 11A. Co-prime Array 数学
地址:http://codeforces.com/contest/660/problem/A 题目: A. Co-prime Array time limit per test 1 second me ...
- Codeforces 946G Almost Increasing Array (树状数组优化DP)
题目链接 Educational Codeforces Round 39 Problem G 题意 给定一个序列,求把他变成Almost Increasing Array需要改变的最小元素个数. ...
- CodeForces - 86D D. Powerful array —— 莫队算法
题目链接:http://codeforces.com/problemset/problem/86/D D. Powerful array time limit per test 5 seconds m ...
- 【Codeforces 722C】Destroying Array (数据结构、set)
题意 输入一个含有 n(1≤n≤100000) 个非负整数的 a 数组和一个 1-n 的排列 p 数组,求每次删除 a[p[i]] 后,最大连续子段和(不能跨越被删除的)是多少? 分析 因为都是非负整 ...
随机推荐
- 163免费邮客户端设置的POP3、SMTP、IMAP地址
网易邮箱支持POP3/SMTP/IMAP服务,方便您可以通过电脑客户端软件更好地收发邮件
- VS2013 打开项目时出现 未定义标识符string的解决办法
---恢复内容开始--- 前两天从前辈那儿弄到一份源码,VC 6时期写出来的mfc程序. 打开之后直接编译编译成功,可以运行.但是看代码的时候却发现出现了好多错误,如 未定义标识符string,NUL ...
- log4j定义某个类的日志级别
项目引入了定时任务后,当我把已有的定时任务删除后,控制台一直会打出类似于 [org.springframework.scheduling.quartz.LocalDataSourceJobStore] ...
- mysql的时间函数
from_unixtime()是MySQL里的时间函数 date为需要处理的参数(该参数是Unix 时间戳),可以是字段名,也可以直接是Unix 时间戳字符串 后面的 '%Y%m%d' 主要是将返回值 ...
- putty 实现不用输入用户名密码直接登陆
多谢谢Eric的教程 ,下面是我的简化版,原版为Eric所写 远程登陆Linux服务器有两大著名软件,一个是商业软件securecrt,一个是开源软件putty. 两者的安全性能都很高,发展了多年,值 ...
- 译文:javascript function中的this
个人理解+google翻译.如有错误,请留言指正.原文来自MDN: this 简介 Javascript中一个函数的this关键字的行为相对其它语言有些不同.在严格模式和非严格模式间也有区别. 在大多 ...
- 【NetOffice Excel】Excel合并单元格【原】
CSharp操作Excel采用开源的原生.NET程序集NetOffice,格式兼容性更好. 在操作Excel的时候有时候需要合并单元格 using ExcelOffice = NetOffice.Ex ...
- phpstorm 自定义函数配置
phpstorm 自定义函数配置 打开设置->活动模板->
- 提高 Discuz 门户文章被百度收录的方法
如果你了解 SEO,你就该清楚使用 canonical URL 标签可以固定网页标准地址,可以提高网页的权重,有利于搜索引擎收录. 例如我的网站拥有两个子域名www.bbseat.com.cn和bbs ...
- 使用saltstack批量部署服务器运行环境事例——批量部署nagios客户端
之前关于搭建web服务器集群实验的这篇文章http://www.cnblogs.com/cjyfff/p/3553579.html中,关于如何用saltstack批量部署服务器这一点当时没有记录到文章 ...