问题 F: Strategy Game
题目描述
A strategy game with J players is played around a table. Players are identified by numbers from 1 to J and will play a total of R rounds.
At each round each player will play once, in the order of their identifiers; that is, player 1 will play first, player 2 will play second, and so on. Once player J plays, the round is complete, and a next round starts.
A player earns a certain amount of Victory Points every time she or he plays. After all rounds are finished the total points of each player is computed as the sum of Victory Points the player earned on
each round. The winner is the player with the maximum number of points; in case of a tie the winner is the player who earned the maximum number of points and played last.
Given the number of players, the number of rounds and a list describing the Victory Points in the order they were obtained, you must determine which player is the winner.
输入
The input contains several test cases. In each test case, the first line contains two integers J and R,respectively the number of players and the number turns (1 ≤ J, R ≤ 500). The second line contains
J ? R integers, representing the Victory Points earned by each player in each turn, in the order they happened. The Victory Points obtained in each turn will be always integer numbers between 0 and 100, inclusive.
输出
For each test case in the input, your program must produce one single line, containing the integer representing the winner.
样例输入
3 3
1 1 1 1 2 2 2 3 3
2 3
0 0 1 0 2 0
样例输出
3
1
题意
有n个人进行m轮游戏,第一行给出人数和回合数,第二行给出n*m个数据,表示n个人在m轮游戏中的分别得分;输出n个人进行m轮游戏后得分最高的人编号,若分数相同则输出后出场的人,即编号大的人。
代码样例
#include<iostream>
#include<algorithm>
using namespace std;
const int N=100010;
struct code{
long long id;long long sum;
}c[N];
bool cmp(code a,code b)
{
if(a.sum!=b.sum) return a.sum>b.sum;return a.id>b.id;
}
int main()
{
long long a,b;while(cin>>a>>b){
long long score[a*b+10]={
0}; for(long long i=0;i<a*b;i++){
cin>>score[i];}for(long long i=0;i<a*b;i++){
c[i%a].sum+=score[i];c[i%a].id=i%a;}sort(c,c+a,cmp);/*for(int i=0;i<a;i++){cout<<c[i].id<<" "<<c[i].sum<<endl;}*/cout<<c[0].id+1<<endl;for(long long i=0;i<a*b;i++){
c[i%a].sum=0;c[i%a].id=0;}}return 0;
}