A. Oath of the Night's Watch
2017-02-22 20:16
169 查看
A. Oath of the Night's Watch
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.
这道题我刚开始被Hack掉了,在于没有判断当N==1时,也就是只有一个数字的时候,还有就是所有数字大小都相等的情况,做这种题,最重要的就是考虑周全,细心。
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
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.
这道题我刚开始被Hack掉了,在于没有判断当N==1时,也就是只有一个数字的时候,还有就是所有数字大小都相等的情况,做这种题,最重要的就是考虑周全,细心。
#include<stdio.h> #include<stdlib.h> #include<string.h> int comp(const void *a,const void *b) { return *(int *)a- *(int *)b; } int a[100010]; int main() { int n,i,j; while(~scanf("%d",&n)) { if(n==1) { scanf("%d",&a[0]); printf("0\n"); } else { for(i=0;i<n;i++) scanf("%d",&a[i]); qsort(a,n,sizeof(int),comp); int min=a[0]; int max=a[n-1]; for(i=0;i<n;i++) if(a[i]>min) break; for(j=n-1;j>=0;j--) if(a[j]<max) break; // 0 1 2 3 4 5 6 if(i>=n || j<0) printf("0\n"); else printf("%d\n",j-i+1); } } return 0; }
相关文章推荐
- 【codeforces 768A】Oath of the Night's Watch
- A. Oath of the Night's Watch
- In the cold of night
- The color of night ---lauren christy
- Jordan - Lord of the details of the night
- Night of the Image Map
- The Prisoner of Zenda——10、A night outside the castle
- P25 (*) Generate a random permutation of the elements of a list.
- C++: How is the process of function calling in C++
- CocoaPods did not set the base configuration of your project 问题解决方式
- Eclipse报错:this compilation unit is not on the build path of a java project
- ≪统计学习精要(The Elements of Statistical Learning)≫课堂笔记(三)
- 集中精力的重要性(The Importance of Focus)
- 关于Out of the box翻译【待整理】
- 539--The Settlers of Catan
- The Adventures of Huckleberry Finn——1、Huck in trouble
- The distinguish of module , class when nested in ruby
- The method of type must override a superclass method解决方式
- UVALive - 6800 The Mountain of Gold?(Bellman-ford找负权回路,dfs)
- make the adidas sandals act of