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的概 ...
随机推荐
- puppet配置问题统计
一. [root@client puppet]# puppetd --test --server master.test.cominfo: Creating a new SSL key for cli ...
- MongoDB数据库详解
第1章 数据库管理系统 1.1 前言 01.数据的定义:文字.图像.地理位置信息(坐标.经纬度)等 02.数据库管理系统的定义:建立.存取和管理数据,保证数据安全和完整性的软件 03.常见的数据库管理 ...
- php gif处理
http://www.jb51.net/article/51702.htm https://github.com/Sybio/GifCreator https://github.com/Sybio/G ...
- detach() 与remove()
detach() 与remove()区别,在于remove()掉后,就没有啦,添加的事件也没有啦,后者还有啊,可以保留的哦,虽然 $("div").click(function() ...
- linux svn up 中文显示乱码解决办法
vi /etc/sysconfig/i18n #LANG="en_US.UTF-8" #LANG=zh_CN.GB18030 #LC_ALL=zh_CN.GB18030 #SYSF ...
- zabbix 3.0.4 中文字体替换
zabbix 对中文支持不是很好,会出现乱码: 从windows系统里 找到字体包:如图: 拷贝到zabbix-server里面,注意,把文件名改成小写: 我linux 是centos7.2版本 [r ...
- Fiddler的script用法
一.关于Fiddler Script Fiddler Script 是用JScript.NET语言写的.Fiddler 包含了一个脚本文件可以自动修改Http Request 和Response.这样 ...
- Elasticsearch强制重置未分配的分片(unassigned)
强制重置未分片的分片,这个问题源自于Elasticsearch维护中,Node意外退出的场景. 意外退出后Elasticsearch由于网络原因或者jvm性能压力,未能短时间内分配分片. 看一下分片的 ...
- Web App、Hybrid App与Native App
在这个App的时代,转战了前端,一直接触的都是pc, 离out不远了. 那么接下来,app是我接下来半年的重点,为什么是半年,因为时间不多了. 因为是前端,那么我的重心肯定是 Web App, Hyb ...
- timeline自适应时间轴
近期项目一直有类似QQ空间那样的时间轴,来展示公司新闻动态,或者流程之类的设计UI. 每每出现,不以为然,这次总结了下,精简下 ================= ================== ...