million contestants:算法分析

本文介绍了一种通过分析参赛者解决任务的数量及时间顺序来确定编程竞赛获胜者的算法。该算法接收一系列接受解决方案的日志,并返回赢得比赛的参赛者编号。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem Statement

 

Exactly one million contestants, numbered 1 through 1,000,000, took part in a programming contest. The rules of the contest are simple: the winner is the contestant who solves the largest number of tasks. If there are more contestants tied for most tasks solved, the winner is the one who was the first to have all of their tasks solved.

During the contest the judges were keeping a log of all accepted solutions. You are given this log as a vector <int> events. The i-th element of events is the number of the contestant who submitted the i-th accepted solution (both indices are 0-based).

For example, if events = {4, 7, 4, 1}, this is what happened during the contest:

  • Contestant 4 solved her first task.
  • Contestant 7 solved his first task.
  • Contestant 4 solved her second task.
  • Contestant 1 solved his first task.

Compute and return the number of the contestant who won the contest.

Definition

 
Class:ContestWinner
Method:getWinner
Parameters:vector <int>
Returns:int
Method signature:int getWinner(vector <int> events)
(be sure your method is public)
 
 

Constraints

-events will contain between 1 and 50 elements, inclusive.
-Each element of events will be between 1 and 1,000,000, inclusive.

Examples

0) 
 
{4,7,4,1}
Returns: 4
Example from the problem statement.
1) 
 
{10,20,30,40,50}
Returns: 10
2) 
 
{123,123,456,456,456,123}
Returns: 456
3) 
 
{1,2,2,3,3,3,4,4,4,4}
Returns: 4

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.     

这个简单的!!


#include<math.h>
#include <cmath>
#include<sstream>
#include<vector>
#include <iostream>
#include <functional>
#include <numeric>
#include<map>
#include <string.h>
#include<stdlib.h>
int h[1000000];
using namespace std;


vector<int > permutation;
class ContestWinner{
public:
int getWinner(vector <int> events){
int w=0;
string s;
for(int i=0;i<events.size ();i++ ){
char str[10];
_itoa_s(events[i],str,10);

s+=str;
s+=' ';
}
istringstream iss(s);
for(int i=0;i<events.size ();i++ ){
int t;
iss>>t;
h[t]++;
if(h[w]<h[t])
w=t;

}


return w;
}


};


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值