Codeforces Round #109 (Div. 2) A. I_love_%username%【打擂台算法/满足当前数字在已经出现的数字的最大值和最小值之间的个数】
2 seconds
256 megabytes
standard input
standard output
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously).
Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictlymore points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him.
The first line contains the single integer n (1 ≤ n ≤ 1000) — the number of contests where the coder participated.
The next line contains n space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000.
Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.
5
100 50 200 150 200
2
10
4664 6496 5814 7010 5762 5736 6944 4850 3698 7242
4
In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing.
【分析】:一串数字,求满足当前数字在已经出现的数字的最大值和最小值之间的个数(严格大于和小于)遍历一次,维护当前的最大值和最小值,然后判断计数就行了。
【代码】:
#include <bits/stdc++.h> using namespace std;
int n,a[],sum,maxx,minx;
int main()
{
while(cin>>n)
{
sum=;
cin>>a[];//!!!
minx=maxx=a[];
for(int i=;i<n;i++)
{
cin>>a[i];
if(a[i]>maxx)
{
sum++;
maxx=a[i];
}
if(a[i]<minx)
{
sum++;
minx=a[i];
}
}
cout<<sum<<endl;
}
return ;
}
数组开大点!
Codeforces Round #109 (Div. 2) A. I_love_%username%【打擂台算法/满足当前数字在已经出现的数字的最大值和最小值之间的个数】的更多相关文章
- codeforces水题100道 第十九题 Codeforces Round #109 (Div. 2) A. I_love_%username% (brute force)
		
题目链接:http://www.codeforces.com/problemset/problem/155/A题意:找到当前最大值或者最小值出现的次数.“当前”的意思差不多是a[i]大于所有a[j]( ...
 - 贪心 Codeforces Round #109 (Div. 2) B. Combination
		
题目传送门 /* 贪心:按照能选的个数和点数降序排序,当条件不符合就break,水题啊! */ #include <cstdio> #include <algorithm> # ...
 - Codeforces Round #109 (Div. 2) E. Double Profiles hash
		
题目链接: http://codeforces.com/problemset/problem/155/E E. Double Profiles time limit per test 3 second ...
 - Codeforces Round #109 (Div. 1) 题解 【ABC】
		
A - Hometask 题意:给你一个字符串,然后再给你k个禁止挨在一起的字符串,问你最少删除多少个字符串,使得不会有禁忌的字符串对挨在一起.题目保证每个字符最多出现在一个禁忌中. 题解:由于每个字 ...
 - Codeforces Round #372 (Div. 2)
		
Codeforces Round #372 (Div. 2) C. Plus and Square Root 题意 一个游戏中,有一个数字\(x\),当前游戏等级为\(k\),有两种操作: '+'按钮 ...
 - Codeforces Round #418 (Div. 2) D. An overnight dance in discotheque
		
Codeforces Round #418 (Div. 2) D. An overnight dance in discotheque 题意: 给\(n(n <= 1000)\)个圆,圆与圆之间 ...
 - cf之路,1,Codeforces Round #345 (Div. 2)
		
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
 - Codeforces Round #262 (Div. 2) 1003
		
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
 - Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset (0/1-Trie树)
		
Vasiliy's Multiset 题目链接: http://codeforces.com/contest/706/problem/D Description Author has gone out ...
 
随机推荐
- +(void)load; +(void)initialize;有什么用处?
			
总得来说: 1.+load方法是在main函数之前调用的: 2.遵从先父类后子类,先本类后列类别的顺序调用: 3.类,父类与分类之间的调用是互不影响的.子类中不需要调用super方法,也不会调用父类的 ...
 - 《Cracking the Coding Interview》——第14章:Java——题目3
			
2014-04-26 18:59 题目:final.finally.finalize有什么区别? 解法:烂大街之java语法题.此题被多少公司考过我不知道,反正我确实遇见过一次了. 代码: // 14 ...
 - Pascal小游戏 文件的产生
			
一个整人的Pascal小程序 运行之后硬盘里面会有一大堆垃圾,当然更好的方法当然不是这样做! var a,b,c,d:char;beginfor a:='0' to '9' dofor b:='0' ...
 - Linux下nginx支持.htaccess文件实现伪静态的方法!
			
在Google上搜索的资料很多人都说nginx目前不支持.htaccess文件,我按照nginx的规则试验了一下,结果发现nginx是完全支持.htaccess文件的! 方法如下: 1. 在需要使用. ...
 - JAVA判断一个字符串里面有没有汉字
			
private static boolean checkIfExistChineseCharacter(String s) { return !(s.length() == s.getBytes(). ...
 - 湘潭邀请赛 2018 E From Tree to Graph
			
题意: 给出一棵树以及m,a,b,x0,y0.之后加m条边{(x1,LCA(x1,y1)),(x2,LCA(x2,y2))...(xm,LCA(xm,ym))}.定义z = f(0)^f(1)^... ...
 - BZOJ3244 [Noi2013]树的计数 【数学期望 + 树遍历】
			
题目链接 BZOJ3244 题解 不会做orz 我们要挖掘出\(bfs\)序和\(dfs\)序的性质 ①容易知道\(bfs\)序一定是一层一层的,如果我们能确定在\(bfs\)序中各层的断点,就能确定 ...
 - C++vector使用
			
标准库Vector类型使用需要的头文件:#include <vector>Vector:Vector 是一个类模板.不是一种数据类型. Vector<int>是一种数据类型. ...
 - C中堆和栈的区别
			
C++中堆和栈的完全解析 内存分配方面: 堆: 操作系统有一个记录空闲内存地址的链表,当系统收到程序的申请时,会遍历该链表,寻找第一个空间大于所申请空间的堆结点,然后将该结点从空闲结点链表中删 除,并 ...
 - Oracle SQL 疑难解析读书笔记(一 基础)
			
1.在语句中找到和消除空值 select first_name,last_name from hr.employees where commission_pct is null is null 和 i ...