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. generic_netlink 用法

    参考资料: https://wiki.linuxfoundation.org/networking/generic_netlink_howto generic_netlink 框架 +-------- ...

  2. UI设计课程教程分享:Banner的设计和技巧

    Banner是一个网站的中心主题,可以从banner看出网站的内容.所以一个好的banner对网站的影响很大. 提高banner的制作从几点深入了解:文字排版.选择适合的图片及背景.颜色的用法. 一. ...

  3. 看起来像是PS的照片,实际上却令人难以置信!

    图片来源:网络 在现实生活中 很多照片看起来不可思议 就像经过PS处理的一样. 今天就跟随米醋一起来感受一下 看这些超现实的真实照片. 一张感光过度的照片, 让狗的头看起来像是悬浮的. 一只被困在琥珀 ...

  4. sqli-labs:17,增删改

    增 insert into users values(','lcamry','lcamry'); 删 delete from users where id=16 删数据库:drop database ...

  5. Angular的一些用法或者结构技巧

    如果有更好的方式,请留言交流: 2017-07-07 多个controller共用一个函数.在$rootScope中定义方法, $rootScope.share_fun = function test ...

  6. ubuntu系统ftp连接 以及ssh连接

    tfp连接 ssh连接 ubuntu下ssh使用 与 SCP 使用 1 ssh远程登录服务器 ssh username@remote_ip #将username换成自己的用户名,将remote_ip换 ...

  7. POI导出大量数据的简单解决方案

    说明:我的电脑 2.0CPU 2G内存 能够十秒钟导出 20W 条数据 ,12.8M的excel内容压缩后2.68M 我们知道在POI导出Excel时,数据量大了,很容易导致内存溢出.由于Excel ...

  8. 数字统计(NOIP2010)

    题目链接:数字统计 这题很水. 思路就是:枚举每一个区间内的数,然后对于每一个数,每个位去判断是否为2,就行了. 下面上代码: #include<bits/stdc++.h> using ...

  9. NYOJ 1016 判断两线段是否相交

    #include<cstdio> #include<cmath> #include<iostream> #include<algorithm> #inc ...

  10. MVCS框架的注意点

    1.Service最好用一个接口对应一个service(便于增加扩展方法) 2.除Services和Model外都需继承自各自对应的父类 3.View不要轻易重写Start和Awake方法(含与启动有 ...