关闭

Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A(贪心)

标签: codeforces
224人阅读 评论(0) 收藏 举报
分类:

A. Oath of the Night’s Watch
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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.

题意:N代表接下来一行有N个数字,找出满足条件的数字X,条件是给定序列中既有比X小的数也有比X大的数,求出满足条件的X的数量。

思路:给定序列排个序,左右两头指针向中间扫描,直至遇到首个满足条件的数停止。

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
const int maxn=100005;
int num[maxn];
int main()
{
    int N;
    scanf("%d",&N);
    for(int i=1;i<=N;i++)
        scanf("%d",&num[i]);
    sort(num+1,num+N+1);
    int left=1,right=N;
    while(left<=right&&num[left+1]==num[left])
        left++;
    while(right>=left&&num[right-1]==num[right])
        right--;
    int result=right-left+1;
    if(result>=3)
        printf("%d\n",result-2);
    else
        printf("0\n");
    return 0;
}
0
0
查看评论

ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) E. The Holmes Children

E. The Holmes Children time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard ...
  • mystery_guest
  • mystery_guest
  • 2017-03-04 18:40
  • 286

Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined)A+B

A. Gotta Catch Em’ All!time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inputoutput:standard outputBash wants to become a...
  • qq_33183401
  • qq_33183401
  • 2017-01-16 17:12
  • 243

Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) A. Gotta Catch Em' All!(水题)

题目链接:http://codeforces.com/contest/757/problem/AA. Gotta Catch Em’ All! time limit per test1 second memory limit per test256 megabytes inputstandar...
  • qq_32866009
  • qq_32866009
  • 2017-01-13 09:17
  • 200

Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) C. Felicity is Coming!组合学+集合

题意:给出n组数,每组gi个数,每个数属于1~m,每个数可以变化但变化前相同的数变化后依然相同,变化前不同的速变化后依然不同,且可能不变,但经过变化后每组的每种数的个数不会变化,求变化的总方案数。 组合学+集合 //这题是根据Codeforces的官方题解写的 把1~m分成一些集合,在同一个集合里的...
  • ProLightsfxjh
  • ProLightsfxjh
  • 2017-01-14 01:28
  • 571

Codeforces Round #258 (Div. 2)-(A,B,C,D,E)

A:Game With Sticks 水题。。。每次操作,都会拿走一个横行,一个竖行。 所以一共会操作min(横行,竖行)次。 #include #include #include #include #include #include #include #include #pragma commen...
  • rowanhaoa
  • rowanhaoa
  • 2014-07-25 14:39
  • 1476

【解题报告】Codeforces Round #401 (Div. 2)

简略的解题报告。
  • TRiddle
  • TRiddle
  • 2017-02-25 17:55
  • 412

Codeforces Round #395 (Div. 2)(ABCD)

ps:打完这场cf才知道自己真的很菜,还是停留在AB题的水平,有时候CD其实很简单,但就是想不到,别人一眼看出而我就是想不到,有时候想到了点子上但就是突破不了 题目链接:  Codeforces Round #395 (Div. 2) A题: &...
  • qq_34731703
  • qq_34731703
  • 2017-02-03 12:50
  • 495

Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) -- C. Destroying Array (并查集)

大体题意: 给你n 个数字,告诉你破坏每个数字的顺序,每次破坏后你要求一个线段,使得线段不包含破坏的点,并且线段上的值和最大? 思路: 正着删除感觉不好处理,就反过来求了,相当于从一个空序列往上面添加数值,加一次,求一次线段的最大和,在加之前,我们可以先定义一个变量Max 表示之前的操作所得到...
  • aozil_yang
  • aozil_yang
  • 2016-10-02 00:37
  • 372

Codeforces Round #400 (Div. 1 + Div. 2, combined)A. A Serial Killer【模拟】

A. A Serial Killer time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Our belove...
  • mengxiang000000
  • mengxiang000000
  • 2017-02-24 12:00
  • 292

Codeforces Round #254 (Div. 1)C. DZY Loves Colors(线段树经典操作/分块)

题目链接 C. DZY Loves Colors time limit per test 2 seconds memory limit per test 256 megabytes input standard input output stan...
  • fouzhe
  • fouzhe
  • 2017-02-11 15:17
  • 283
    个人资料
    • 访问:142163次
    • 积分:5531
    • 等级:
    • 排名:第5729名
    • 原创:415篇
    • 转载:6篇
    • 译文:0篇
    • 评论:46条
    最新评论