Description

Gibbs: Next!
First Pirate: My wife ran off with my dog and I'm drunk for a month.

Gibbs: Perfect. Next!

Second Pirate: Me have one arm and a bum leg.

Gibbs: It's the crow's nest for you. Next!
In Tortuga the Captain Jack Sparrow and Will Turner set up an excellent
team. And now Jack wants to elect a captain's mate — the most worthy
pirate in the new crew, who has fewer disadvantages and can be a role
model for the rest.
Without thinking a lot Jack decided to use the following uncomplicated
plan to choose the best pirate of the crew. Firstly, he ranks n
contenders in one long row, beckons the first one and this first pirate
is a current contender to be the mate. Then Jack walks along the row and
stares at everybody one by one. He compares the regular pirate with the
current contender and if he sees that the regular pirate has fewer
disadvantages, then he changes the current contendor to the regular
pirate. In the end of this process the new mate will stand near Jack.
Will knows about Jack’s plan and wants to count what pirate will have
most comparisons while Jack elects. Let’s help Will with his
calculations.

Input

The first line contains an integer n that is the number of pirates in the crew (1 ≤
n ≤ 10 5). Next line contains n integers:
a1,
a2, …,
an, where ai is the number of disadvantages of i-th contender in Jack's opinion (1 ≤
ai ≤ 10 9). The pirates are
numbered in the way they stood in the row in the beginning of the
elections. It is guaranteed that the numbers of disadvantages, which the
pirates have, are pairwise different.

Output

Output the number of a pirate who was compared with others maximal
number of times. If there are several such pirates, you can output any
of them.

Sample Input

input output
6
2 5 3 4 1 9
1
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define MM 100005
struct st
{
int num;
int count;
} a[MM]; int main()
{
int n,min,i,temp,flag,max=; while(~scanf("%d",&n))
{
max=-;
memset(a,,sizeof a);
scanf("%d",&a[].num);
min=a[].num;
temp=;
for(i=; i<n; i++)
{
scanf("%d",&a[i].num);
if(a[i].num>=min) ///相当于从后往前看了 每一次都更新一遍 最后总结
{
a[temp].count++; ///0的
a[i].count++; ///0之后的
}
else
{
min=a[i].num; ///替换
a[temp].count++; ///0的
a[i].count++;///0之后的
temp=i; ///记录编号 }
}
for(i=; i<n; i++) ///比较
{ if(max<a[i].count)
{
max=a[i].count;
flag=i+;
}
}
printf("%d\n",flag); ///输出
} return ;
}
#include <iostream>
#include <string.h>
#include <stdio.h> using namespace std;
int a[]; int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
int j=,i;
int num=;
int max=;
int ans=;
for(i=;i<=n;i++)
{ if(a[j]<a[i])
{
num++;
}
else
{
num++;
if(max<num)
{
max=num;
ans=j;
}
j=i;
num=;
}
}
if(num>max) ans=j;
printf("%d\n",ans);
}
return ;
}

A - Excellent Team的更多相关文章

  1. 计算机本科/硕士找offer的总结 节选

    在这样的目标定位下,我的求职历程从2006年10月8日开始,到2007年1月10日正式结束,一共持续了3个月的时间.整个过程可以分为三个阶段:第一阶段:2006年10月份 找工作刚刚开始的阶段,什么都 ...

  2. 一些公司对quantitative的要求

    来自日月光华BBS: Company: UBS AG Job Title: Quantitative Developers / Analysts (Entry Level, Multiple Posi ...

  3. L219 China's office workers consider further education, training essential

    More than 90 percent of China's office workers consider on-the-job training and continuing education ...

  4. Ten Qualities of an Effective Team Player

    If you were choosing team members for a business team in your organization, who would the best team ...

  5. Excellent JD

    Job description About the role We are looking for a talented engineer who has excellent cloud skills ...

  6. Configure a VLAN on top of a team with NetworkManager (nmcli) in RHEL7

    SOLUTION VERIFIED September 13 2016 KB1248793 Environment Red Hat Enterprise Linux 7 NetworkManager ...

  7. Create a Team in RHEL7

    SOLUTION VERIFIED September 13 2016 KB2620131 Environment Red Hat Enterprise Linux 7 NetworkManager ...

  8. Team Leader 你不再只是编码, 来炖一锅石头汤吧

    h3{ color: #000; padding: 5px; margin-bottom: 10px; font-weight: bolder; background-color: #ccc; } h ...

  9. Configure bridge on a team interface using NetworkManager in RHEL 7

    SOLUTION IN PROGRESS February 29 2016 KB2181361 environment Red Hat Enterprise Linux 7 Teaming,Bridg ...

随机推荐

  1. 杭电1518 Square(构成正方形) 搜索

    HDOJ1518 Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. Ubuntu下Tomcat绑定80端口(zz)

    Ubuntu下Tomcat绑定80端口 来源:本站转载 作者:佚名 时间:2011-02-22 TAG: 工作环境迁移到了Ubuntu,很多东西发生了变化,比如原先配置tomcat端口.只需要配置se ...

  3. Angular学习笔记:Angular CLI

    定义 Angular CLI:The Angular CLI is a command line interface tool that can create a project, add files ...

  4. 2019.01.21 bzoj3674: 可持久化并查集加强版(主席树+并查集)

    传送门 题意:维护可持久化并查集,支持在某个版本连边,回到某个版本,在某个版本 询问连通性. 思路: 我们用主席树维护并查集fafafa数组,由于要查询历史版本,因此不能够用路径压缩. 可以考虑另外一 ...

  5. Educational Codeforces Round 61 D 二分 + 线段树

    https://codeforces.com/contest/1132/problem/D 二分 + 线段树(弃用结构体型线段树) 题意 有n台电脑,只有一个充电器,每台电脑一开始有a[i]电量,每秒 ...

  6. TCP/IP协议(2):各层网络设备

    一.中继器(Repeater) 中继器工作在OSI的一层物理层,我们知道,超5类线的传输距离最大为100米,超过这个距离信号就会衰减,中继器就是为了防止信号变差,将网络信号进行再生和重定时. 二.集线 ...

  7. nginx负载均衡的5种策略

    nginx可以根据客户端IP进行负载均衡,在upstream里设置ip_hash,就可以针对同一个C类地址段中的客户端选择同一个后端服务器,除非那个后端服务器宕了才会换一个. nginx的upstre ...

  8. 华为机试-iNOC产品部-杨辉三角的变形

    题目描述 1 1 1 1 1 2 3 2 1 1 3 6 7 6 3 11 4 10 16 19 16 10 4 1以上三角形的数阵,第一行只有一个数1,以下每行的每个数,是恰好是它上面的数,左上角数 ...

  9. Attr类型

    Attr表示元素的特性,在所有浏览器中,都可以访问Attr类型的构造函数和原型. attr特性存在于元素的attributes属性中的节点 nodeType 2 nodeName 特性的名称 node ...

  10. javascript总结集合

    前言:下面的总结都是自己测试过的,绝大多数都是没问题的,但是不敢保证一定全面,还需要诸君自己独立思考: 1)基础:在nodejs里全局对象是global,而网页里js的全局对象是window:对于所有 ...