A. Second Order Statistics
来源:互联网 发布:mac 梦幻西游手游网页 编辑:程序博客网 时间:2024/05/22 05:22
A. Second Order Statistics
time limit per test
2 secondsmemory limit per test
256 megabytesinput
standard inputoutput
standard outputOnce Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
Input
The first input line contains integer n (1?≤?n?≤?100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
Output
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
Sample test(s)
input
4
1 2 2 -4
output
1
input
5
1 2 3 1 1
output
2
/* ***********************************************
Author :
Created Time :2015/6/11 20:04:16
File Name :7.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 1<<30
#define maxn 10000+10
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
bool cmp(int a,int b){
return a>b;
}
int a[maxn];
map<int,int>mp;
int main()
{
#ifndef ONLINE_JUDGE
//freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int n;
while(cin>>n){
int cnt=0;
for(int i=0;i<n;i++){
cin>>a[i];
if(mp[a[i]]==0){
mp[a[i]]++;
cnt++;
}
}
if(cnt<2)cout<<"NO"<<endl;
else {
sort(a,a+n);
unique(a,a+n);
cout<<a[1]<<endl;
}
}
return 0;
}
#include <cmath>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <functional>
#include <map>
#include <set>
using namespace std;
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define zero(a) memset(a, 0, sizeof(a))
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector <int> vi;
typedef pair <int, int> pii;
const int maxn = (int)1e5 + 10;
int n, a[maxn];
int main()
{
scanf("%d", &n);
forn(i, n)
scanf("%d", &a[i]);
sort(a, a + n);
if (unique(a, a + n) - a < 2)
puts("NO");
else
printf("%d\n", a[1]);
return 0;
}
0 0
- A. Second Order Statistics
- A. Second Order Statistics
- 【水hash】#22 A. Second Order Statistics
- Codeforces 22A-Second Order Statistics(题意)
- CodeForces 22A Second Order Statistics (简单题)
- Order statistics
- Lecture 6 Order Statistics
- Medians and Order Statistics
- HSOG: A Novel Local Image Descriptor Based on Histogram of the Second-Order Gradients
- A. Second-price Auction
- A New View of Statistics
- order statistics(找最ith小数值)问题
- MIT算法导论学习-Lecture6 顺序统计问题(Order Statistics)
- SPD matrix features: Semantic segmentation with second-order pooling
- DE11 Theory of General Second-order Linear Homogeneous ODEs
- [线性常微分方程][6]second order linear equations
- second
- second
- A. Noldbach problem
- A. Triangle
- A. World Football Cup
- A. BerOS file system
- A. Jabber ID
- A. Second Order Statistics
- A. You\'re Given a String...
- A. Ring road
- A. IQ test
- A. Almost Prime
- A. Next Test
- Oracle内置表二
- A. Spit Problem
- A. Accounting