A - Excellent Team
Description
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!
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.
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.
most comparisons while Jack elects. Let’s help Will with his
calculations.
Input
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
number of times. If there are several such pirates, you can output any
of them.
Sample Input
| input | output |
|---|---|
6 |
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的更多相关文章
- 计算机本科/硕士找offer的总结 节选
在这样的目标定位下,我的求职历程从2006年10月8日开始,到2007年1月10日正式结束,一共持续了3个月的时间.整个过程可以分为三个阶段:第一阶段:2006年10月份 找工作刚刚开始的阶段,什么都 ...
- 一些公司对quantitative的要求
来自日月光华BBS: Company: UBS AG Job Title: Quantitative Developers / Analysts (Entry Level, Multiple Posi ...
- 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 ...
- 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 ...
- Excellent JD
Job description About the role We are looking for a talented engineer who has excellent cloud skills ...
- 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 ...
- Create a Team in RHEL7
SOLUTION VERIFIED September 13 2016 KB2620131 Environment Red Hat Enterprise Linux 7 NetworkManager ...
- Team Leader 你不再只是编码, 来炖一锅石头汤吧
h3{ color: #000; padding: 5px; margin-bottom: 10px; font-weight: bolder; background-color: #ccc; } h ...
- 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 ...
随机推荐
- 洛谷2971 [USACO10HOL]牛的政治Cow Politics
原题链接 假设只有一个政党,那么这题就退化成求树的直径的问题了,所以我们可以从此联想至\(k\)个政党的情况. 先处理出每个政党的最大深度,然后枚举每个政党的其它点,通过\(LCA\)计算长度取\(\ ...
- Unknown type name 'NSString' 解决方案
今天看到个问题,编辑工程提示Unknown type name 'NSString',如下图 导致出现异常的原因是是因为工程中添加了ZipArchive(第三方开源解压缩库) 一般情况下出现“Unkn ...
- libpcap 库使用(二)
参考资料: http://www.tcpdump.org/manpages/pcap.3pcap.html 分类介绍了该lib的函数 Opening a capture handle for read ...
- Using The jQuery Migrate Plugin
jQuery( html [, ownerDocument ] )Returns: jQuery Description: Creates DOM elements on the fly from t ...
- 工具类Utils的单元测试方式
数据质量功能已经开发完毕,但是要实现单元测试覆盖率80%以上,其他的还好,只是这个工具类实在让我摸不着头脑,其实工具类的单元测试是最简单的,只是自己想复杂了而已: 无返回值模拟: 有返回值模拟: 异常 ...
- service fabric重装电脑后集群失败
前提.下载service fabric sdk工具 1.Remote Procedure Call (RPC)服务打开 自动 2.Remote Procedure Call (RPC) Locator ...
- file-downloader相关问题
2017-05-24 file-downloader框架中,如果你想用FileDownloader中的createAndStart(String url, String saveDir, String ...
- js循环遍历数组
一维数组的遍历 <script> //循环遍历数组 var animals = ["cat",'dog','human','whale','seal']; var an ...
- ubuntu配置ftp server
ubuntu配置ftp server 1. 安装vsftpd sudo apt-get install vsftpd 安装后会自动新建一个用户ftp,密码ftp,作为匿名用户登录的默认用户 sud ...
- Linux 在文档中查找满足条件的行并输出到文件:
Linux 在文档中查找满足条件的行并输出到文件: 文件名称: dlog.log 输出文件: out.log 1.满足一个条件(包含 “TJ” )的语句: grep “TJ” dlog. ...