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的概 ...
随机推荐
- PL/SQL Developer使用技巧(部分)
PL/SQL Developer使用技巧(部分) 关键字自动大写 在sql命令窗口中输入SQL语句时,想要关键字自动大写,引人注目该怎么办呢? 一步设置就可以达成了.点击Tools->Prefe ...
- npm的使用总结
npm常用命令 npm list 查看当前目录下已安装的包 npm root -g 查看全局安装的包的路径 npm help 查看全部命令 npm update/uninstall moduleNam ...
- magento获取商品的图片
获取商品的图片主要从catalog_product_entity_media_gallery 表中 该表中各列的属性代表 value_id:记录 ID,可以留空让数据库自动生成. attribute_ ...
- 开启tomcat的apr模式,并利用redis做tomcat7的session的共享。
更新系统组件 yum -y install readline* xmlto kernel-devel yum* screen vim* psmisc wget lrzsz pcre-devel lib ...
- js的Date对象
1.构造Date对象 var dt = new Date(); //获取当地包含日期和时间的对象,格式为:Thu Aug 31 2017 09:15:43 GMT+0800 (中国标准时间) 2.使用 ...
- vi 和vim 的区别
它们都是多模式编辑器,不同的是vim 是vi的升级版本,它不仅兼容vi的所有指令,而且还有一些新的特性在里面.vim的这些优势主要体现在以下几个方面:1.多级撤消我们知道在vi里,按 u只能撤消上次命 ...
- Linux第七节随笔 diff /uniq /stat
linux第七讲(上)1.diff link 作用:diff命令能比较单个文件或者目录内容.如果指定比较的是文件,则只有当输入为文本文件时才有效.以逐行的方式,比较文本文件的异同处. 如果指定比较的是 ...
- Xamarin调用JSON.net来解析JSON
https://www.cnblogs.com/zjoch/p/4458516.html 再来我们要怎么解析JSON格示呢?在.net 中,我们很孰悉的JSON.net,没错,我们依然可以在X ...
- Swift语言中与C/C++和Java不同的语法(三)
这一部分的主要内容是Swift中的Collections 我们知道Java中的Collection基本上是每一个Java程序猿接触到的第一个重要的知识点. 在Swift中也不例外,Swift中的Col ...
- [SharePoint Online]SharePoint Designer无法打开世纪互联版sp online站点得解决方法,报错信息:请安装更新后再重新打开
现象描述: 装了个x64版SharePoint designer 2013, 没有装SP1,在打开国际版得office 365 online得时候完全没有问题,但是在打开世纪互联版得时候就打不开,让安 ...