zoukankan      html  css  js  c++  java
  • 768A Oath of the Night's Watch

    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
    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.

     1 #include <iostream>
     2 #include <algorithm>
     3 using namespace std;
     4 #define LL long long
     5 const LL H=1e6+10;
     6 LL a[H];
     7 int main()
     8 {
     9     int n;
    10     cin >> n;
    11     for(int i = 0; i < n; i++)
    12     {
    13         cin >> a[i];
    14     }
    15     sort(a, a + n);
    16     int ans = 0;
    17     if(n <= 2)
    18         cout << 0 << endl;
    19     else {
    20         for(int i = 1; i < n-1;i++)
    21         {
    22             if((a[i] > a[0]) && (a[i] < a[n-1]))
    23                 ans ++;
    24         }
    25         cout << ans << endl;
    26     }
    27     return 0;
    28 }
  • 相关阅读:
    js-高级06-正则
    js-高级05-javaScript处理机制
    js-高级04-函数高级应用
    js-高级03-面向对象的继承
    js-高级02-贪吃蛇案例分析
    js-高级01面向对象及创建对象
    js-API 06 高级动画二
    js-API 05 高级动画
    对象数组 数组对象 增删改查 数组
    jQuery ajax请求 一般请求和自定义请求
  • 原文地址:https://www.cnblogs.com/jxust-jiege666/p/6515869.html
Copyright © 2011-2022 走看看