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. NC 5系自定义显示公式

    1.继承NcInnerFunction(nc.vo.pub.formulaset.function.NcInnerFunction) 在方法中引用父类方法function,并在里面写方法 @Overr ...

  2. Java SE EE ME用处

    Java SE: 又称J2SE,开发部署桌面应用程序: Java EE:又称J2EE,开发网站 Java ME:是做手机APP开发 EE在SE基础上构建,提供web服务.组件模型.管理和通信API

  3. nginx gzip on 无效

    优化页面的时候,使用nginx开启gzip ,发现并没有什么反映~ 在nginx.conf中的配置如下: gzip on; gzip_min_length 1k; gzip_buffers 16k; ...

  4. easyui validate -- radio、checkbox 校验扩展,事件域名

    事件域名: $(dom).on('click.myNameSpace',function(){ ... }),其中‘.myNameSpace’便是域名: 目前作用:$(dom).off('click. ...

  5. Java SE学习【二】——面向对象

    面向对象的学习也进行了一段时间,这段时间学了,类和对象:属性:方法:封装:继承:多态:接口.也算是有一些自己的理解,不愧是贴近人类思维的思想,老师讲时我常常会想到以前的一些事物和其交相印证,其中最常想 ...

  6. setInterval与setTimeout 的区别

    setInterval在执行完一次代码之后,经过了那个固定的时间间隔,它还会自动重复执行代码,而setTimeout只执行一次那段代码     用法: setInterval("alert( ...

  7. 50.IOS上传APP问题

    更新版本的时候遇到几个问题 1.ERROR ITMS-90535: "Unexpected CFBundleExecutable Key. The bundle at 'Payload/di ...

  8. 2018.10.26 NOIP模拟 图(最小生成树+线段树合并)

    传送门 首先最开始说的那个一条路径的权值就是想告诉你两个点之间的贡献就是瓶颈边的权值. 那么肯定要用最小生成树算法. 于是我考场上想了30min+30min+30min+的树形dpdpdp 发现转移是 ...

  9. c#利用循环将类实例化为对象

    参考:https://yq.aliyun.com/wenzhang/show_6121 上面的代码每次使用前并没有实例化,会报错,实例化以下就好了,参考:http://bbs.csdn.net/top ...

  10. java学习1ATM

    package atm_1; import java.awt.SystemTray;import java.nio.charset.CharsetEncoder;import java.util.Sc ...