Codeforces 768A Oath of the Night's Watch
"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?
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 a single integer representing the number of stewards which Jon will feed.
2
1 5
0
3
1 2 5
1
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.
题目链接:http://codeforces.com/problemset/problem/768/A
分析:把数字排下序,取最大值和最小值,然后分别进行比较,用一个数去计算其个数即可!
下面给出AC代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
int a[];
while(scanf("%d",&n)!=EOF)
{
int ans=;
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
sort(a+,a++n);
if(n==||n==)
printf("0\n");
if(n>=)
{
int minn=a[];
int maxn=a[n];
for(int i=;i<=n-;i++)
if(a[i]>minn&&a[i]<maxn)
ans++;
printf("%d\n",ans);
}
}
return ;
}
Codeforces 768A Oath of the Night's Watch的更多相关文章
- Codeforces 768A Oath of the Night's Watch 2017-02-21 22:13 39人阅读 评论(0) 收藏
A. Oath of the Night's Watch time limit per test 2 seconds memory limit per test 256 megabytes input ...
- 【codeforces 768A】Oath of the Night's Watch
[题目链接]:http://codeforces.com/contest/768/problem/A [题意] 让你统计这样的数字x的个数; x要满足有严格比它小和严格比它大的数字; [题解] 排个序 ...
- 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 ...
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A. Oath of the Night's Watch
地址:http://codeforces.com/problemset/problem/768/A 题目: A. Oath of the Night's Watch time limit per te ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
随机推荐
- sqlserver 存储过程 分页搜索查询
具体调用实例见代码最后一行注释区域 --if exists(select * from sysobjects where id = object_id(N'page_search') and type ...
- 【Zookeeper】源码分析之服务器(五)之ObserverZooKeeperServer
一.前言 前面分析了FollowerZooKeeperServer,接着分析ObserverZooKeeperServer. 二.ObserverZooKeeperServer源码分析 2.1 类的继 ...
- 从头开始搭建一个Spring boot+ActiveMQ高可用分布式环境
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- ArcGIS 网络分析[2.1] 最短路径
最短路径求解 [如果看到此博客还没有网络数据集的,请参考第一章的内容,点击我,看目录] 最短路径,是什么最短?时间最短?距离最短?什么距离?路程距离? 考虑到拥堵问题,限速问题,换乘问题,在现实的最短 ...
- ArcGIS 网络分析[1.1] 创建用于网络分析用的线类型shp文件[这个太基础了吧!]
具体的准备,在上一篇就说过了,不再赘述. 阅读本篇前,需要的预备知识是:ArcGIS创建各种矢量数据的方法,了解地理坐标与投影坐标 本篇只创建单一的线数据,至于点数据,以后进行复杂的网络分析时再添加进 ...
- 干货分享!关于APP导航菜单设计你应该了解的一切
导航菜单是人机交互的最主要的桥梁和平台,主要作用是不让用户迷失方向.现在市面上产品的菜单栏种类繁多,到底什么样的才是优秀的导航菜单设计呢?好的菜单设计不仅能提升整个产品的用户体验,而且还能让用户耳目一 ...
- 测试xss
<script>window.onload=function(){ alert('加载完毕');}</script>
- find + xargs + cp 遇到文件名中带空格如何处理
一,需求为查询文件名为ZRSH开头的时间为7月至今的所有文件并打包 1.首先想到的就是find + xargs + cp 格式.. find 2016073* -type f -name *ZRS ...
- Django ORM详解
ORM:(在django中,根据代码中的类自动生成数据库的表也叫--code first) ORM:Object Relational Mapping(关系对象映射) 我们写的类表示数据库中的表 我们 ...
- composer安装laravel
安装composer composer是一个很有用的工具,我将用它在本机(win7)上安装laravel 到composer的官网,根据自己的系统要求下载相应的版本 安装laravel 首先cmd下进 ...