A - Excellent Team

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: a 1, a 2, …, a n, where a i is the number of disadvantages of i-th contender in Jack's opinion (1 ≤ a i ≤ 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

inputoutput
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=0;

    while(~scanf("%d",&n))
    {
        max=-1;
        memset(a,0,sizeof a);
        scanf("%d",&a[0].num);
        min=a[0].num;
        temp=0;
        for(i=1; 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=0; i<n; i++) ///比较
        {

            if(max<a[i].count)
            {
                max=a[i].count;
                flag=i+1;
            }
        }
        printf("%d\n",flag);  ///输出
    }

    return 0;
}

 

#include <iostream>
#include <string.h>
#include <stdio.h>

using namespace std;
int a[100000];

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
        int j=1,i;
        int num=0;
        int max=0;
        int ans=1;
        for(i=2;i<=n;i++)
        {

            if(a[j]<a[i])
            {
                num++;
            }
            else
            {
                num++;
                if(max<num)
                {
                    max=num;
                    ans=j;
                }
                j=i;
                num=1;
            }
        }
        if(num>max)   ans=j;
        printf("%d\n",ans);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/zhangying/p/3930769.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The OpenStack Foundation supported the creation of this book with plane tickets to Austin, lodging (including one adventurous evening without power after a windstorm), and delicious food. For about USD $10,000, we could collaborate intensively for a week in the same room at the Rackspace Austin office. The authors are all members of the OpenStack Foundation, which you can join. Go to the Foundation web site. We want to acknowledge our excellent host Rackers at Rackspace in Austin: Emma Richards of Rackspace Guest Relations took excellent care of our lunch orders and even set aside a pile of sticky notes that had fallen off the walls. Betsy Hagemeier, a Fanatical Executive Assistant, took care of a room reshuffle and helped us settle in for the week. The Real Estate team at Rackspace in Austin, also known as “The Victors,” were super responsive. Adam Powell in Racker IT supplied us with bandwidth each day and second monitors for those of us needing more screens. On Wednesday night we had a fun happy hour with the Austin OpenStack Meetup group and Racker Katie Schmidt took great care of our group. We also had some excellent input from outside of the room: Tim Bell from CERN gave us feedback on the outline before we started and reviewed it mid-week. Sébastien Han has written excellent blogs and generously gave his permission for re-use. Oisin Feeley read it, made some edits, and provided emailed feedback right when we asked. Inside the book sprint room with us each day was our book sprint facilitator Adam Hyde. Without his tireless support and encouragement, we would have thought a book of this scope was impossible in five days. Adam has proven the book sprint method effectively again and again. He creates both tools and faith in collaborative authoring at www.booksprints.net. We couldn’t have pulled it off without so much supportive help and encouragement.
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值