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的更多相关文章

  1. Codeforces 442C Artem and Array(stack+贪婪)

    题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数.删除一个数的得分为两边数的最小值,假设左右有一边不存在则算作0分. 问最大得分是多少. ...

  2. Codeforces Round #504 D. Array Restoration

    Codeforces Round #504 D. Array Restoration 题目描述:有一个长度为\(n\)的序列\(a\),有\(q\)次操作,第\(i\)次选择一个区间,将区间里的数全部 ...

  3. 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 ...

  4. Codeforces 754A Lesha and array splitting(简单贪心)

    A. Lesha and array splitting time limit per test:2 seconds memory limit per test:256 megabytes input ...

  5. Codeforces 408 E. Curious Array

    $ >Codeforces \space 408 E. Curious Array<$ 题目大意 : 有一个长度为 \(n\) 的序列 \(a\) ,\(m\) 次操作,每一次操作给出 \ ...

  6. 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 ...

  7. Codeforces 946G Almost Increasing Array (树状数组优化DP)

    题目链接   Educational Codeforces Round 39 Problem G 题意  给定一个序列,求把他变成Almost Increasing Array需要改变的最小元素个数. ...

  8. CodeForces - 86D D. Powerful array —— 莫队算法

    题目链接:http://codeforces.com/problemset/problem/86/D D. Powerful array time limit per test 5 seconds m ...

  9. 【Codeforces 722C】Destroying Array (数据结构、set)

    题意 输入一个含有 n(1≤n≤100000) 个非负整数的 a 数组和一个 1-n 的排列 p 数组,求每次删除 a[p[i]] 后,最大连续子段和(不能跨越被删除的)是多少? 分析 因为都是非负整 ...

随机推荐

  1. Could not delete folder on Win7

    I had the same problem on Win 7 and this worked for me in command prompt. Solution 1: RD/S pathname ...

  2. 为mapcontrol中的图层设置透明度

    ILayer pLayer = axMapControl1.get_Layer(); ILayerEffects pLayerEffects = (ILayerEffects)pLayer; pLay ...

  3. Linux一

    1,debian默认需要手动开启SSH连接# Authentication:LoginGraceTime 120PermitRootLogin without-passwordStrictModes ...

  4. Libcurl笔记三

    一,post请求和回报处理 //"host/path?extra" //strHttp=" http://portal.liuhan.com:/web/getConfig ...

  5. linux之gdb使用

    gdb是linux下用来调试的一款软件,在这里,我只记录平常经常会用到的知识点,用到什么,就记录什么,在调试环境中去熟悉调试方法和调试工具,这才会加深理解. gdb能够做什么?它可以按照你的定义,随心 ...

  6. Adobe Photoshop CS4 Extended CS4 激活序列号

    Adobe Photoshop CS4 Extended CS4 激活序列号(SN):1330-1779-4488-2103-6954-09161330-1170-1002-7856-5023-077 ...

  7. jquery nicescroll 配置参数

    jQuery滚动条插件兼容ie6+.手机.ipad http://www.areaaperta.com/nicescroll/ jQuery(function($){ $("#scrollI ...

  8. MongoDB在windows下安装配置

    MongoDB的官网是:http://www.mongodb.org/ MongoDB最新版本下载在官网的DownLoad菜单下:http://www.mongodb.org/downloads 本人 ...

  9. YII千万级PV架构经验分享--理论篇

    hello,大家好,我是方少,现在想象一下这样一个情景,这是一个很惬意的季节,是一个可以随意乱穿的季节,两个人,一个穿羽绒服,一个穿热裤,小胡同里两人迎面走来,看到对方都哈哈大笑,前仰后合,笑完都甩一 ...

  10. ligerGrid 取得选中行的数据

    var SelectUserIdArr = []; function GetData() { var returnValue = ""; var grid = $("#m ...