A. Oath of the Night's Watch
2017-02-26 22:32
267 查看
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my
post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath.
With that begins the watch of Jon Snow. He is assigned the task to support the stewards.
This time he has n stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a
steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.
Can you find how many stewards will Jon support?
Input
First line consists of a single integer n (1 ≤ n ≤ 105)
— the number of stewards with Jon Snow.
Second line consists of n space separated integers a1, a2, ..., an (0 ≤ ai ≤ 109)
representing the values assigned to the stewards.
Output
Output a single integer representing the number of stewards which Jon will feed.
Examples
input
output
input
output
Note
In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and
he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and
greater than 2.
解题说明:水题,找到最大最小,然后求属于中间的值。
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
long int n,i,j,mini,maxi,ans=0;
scanf("%ld",&n);
long int a[100001];
for(i=0;i<n;i++)
{
scanf("%ld",&a[i]);
}
mini=a[0];
maxi=a[0];
for(i=1;i<n;i++)
{
if(a[i]<mini)
{
mini=a[i];
}
if(a[i]>maxi)
{
maxi=a[i];
}
}
for(i=0;i<n;i++)
{
if(a[i]>mini && a[i]<maxi)
{
ans++;
}
}
printf("%ld\n",ans);
return 0;
}
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my
post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath.
With that begins the watch of Jon Snow. He is assigned the task to support the stewards.
This time he has n stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a
steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.
Can you find how many stewards will Jon support?
Input
First line consists of a single integer n (1 ≤ n ≤ 105)
— the number of stewards with Jon Snow.
Second line consists of n space separated integers a1, a2, ..., an (0 ≤ ai ≤ 109)
representing the values assigned to the stewards.
Output
Output a single integer representing the number of stewards which Jon will feed.
Examples
input
2 1 5
output
0
input
3 1 2 5
output
1
Note
In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and
he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and
greater than 2.
解题说明:水题,找到最大最小,然后求属于中间的值。
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
long int n,i,j,mini,maxi,ans=0;
scanf("%ld",&n);
long int a[100001];
for(i=0;i<n;i++)
{
scanf("%ld",&a[i]);
}
mini=a[0];
maxi=a[0];
for(i=1;i<n;i++)
{
if(a[i]<mini)
{
mini=a[i];
}
if(a[i]>maxi)
{
maxi=a[i];
}
}
for(i=0;i<n;i++)
{
if(a[i]>mini && a[i]<maxi)
{
ans++;
}
}
printf("%ld\n",ans);
return 0;
}
相关文章推荐
- 【codeforces 768A】Oath of the Night's Watch
- A. Oath of the Night's Watch
- The Prisoner of Zenda——10、A night outside the castle
- The value of CFBundleShortVersionString in your WatchKit app's Info.plist (1.0) does not match
- the macro of watch variable value and its memory content
- Book Review of Dynamics of Software Development--Watch the ratio
- gdb教程:2. How do I watch the execution of my program?
- In the cold of night
- Night of the Image Map
- The color of night ---lauren christy
- Jordan - Lord of the details of the night
- 深入学习heritrix---体系结构(Overview of the crawler)
- PowerTip of the Day from powershell.com上周汇总(七)
- (翻译)Tricks of the windows game programming Gurus(Windows游戏大师之路) --- 前言(作者:ANDRE LAMOTHE 1999)
- Android问题:Description Resource Path Location Type Cannot reduce the visibility of the inherited meth
- uva 437 The Tower of Babylon
- TACAS(International Conference on Tools and Algorithms for the Construction and Analysis of Systems)到底是什么档次的会议?
- [Recompose] Set the HTML Tag of a Component via a Prop using Recompose
- Lisp的本质(The Nature of Lisp)
- Relationship of the this pointer and (non-)const member function