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]] 后,最大连续子段和(不能跨越被删除的)是多少? 分析 因为都是非负整 ...
随机推荐
- IOS 解析XML--使用NSXML
一.解析文档顺序触发的函数 1.parserDidStartDocument,在文档的时候触发. 2.parser:didStartElement:namespaceURI:qualifiedName ...
- C 再识数组指针 指针数组的概念
参考出处: http://www.cnblogs.com/mq0036/p/3382732.html http://www.cnblogs.com/hongcha717/archive/2010/10 ...
- myeclipse 的 working set
想必大家的myeclipse会有很多工程看的和不方便,那么怎么让它看的简洁一点呢,使用working set 会让你的目录看起来没有那么的多. 首先是怎么创建 working set ,在新建时选择 ...
- ajax 内部值 外部调用不了原因
var id=‘123’; $.ajax({ url:’http://www.xxx.com/ajax', type:'post', dataType: "json", data: ...
- 判断浏览器js代码
(function(){ var UA = {}; var ua = navigator.userAgent.toLowerCase(),s; UA.ie = (s = ua.match(/(msie ...
- KnockoutJS(3)-绑定语法
绑定语法大致分为2种: 1. 数据绑定(data-bind syntax) 2. 绑定上下文(Binding Context) 下面针对这2中绑定语法分别介绍一下 1. 绑定上下文(Binding C ...
- present的时候是可以直接回到第一个viewcon的
最新:我并没有记错,是可以直接回到的 [self.presentingViewController.presentingViewController dismissModalViewControlle ...
- asp.net get server control id from javascript
var WhateverValue = document.getElementById('<%= saveValue.ClientID %>').value
- Web开发——Http协议剖析
Http,即超文本传输协议,是建立在TCP/IP协议的基础上.在Web开发的过程中,Http协议是十分重要的,浏览器与服务器之间的交互就是基于Http协议的.Http协议如果展开全面讲解会有很多内容, ...
- RabbitMQ基础总结
MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法.应用程序通过读写出入队列的消息(针对应用程序的数据)来通信,而无需专用连接来链接它们.消 息传递指的是程序之 ...