Codeforces 570 A. Elections

Source: Internet
Author: User

Click here ~ ~

A. Elections***the Country ofByalechinsk is running elections involving n candidates. The country consists ofM cities. We know how many peopleinch  eachCity voted for  eachCandidate. The electoralsystem inch  theCountry is pretty unusual. At the  FirstStage ofElections theVotes is counted for  eachCityitis assumed thatinch  eachCity won theCandidate who got theHighest Number  ofVotesinchThis city, and ifSeveral candidates got theMaximum Number  ofVotes, Then  theWinner is the  One  with aSmaller index. At the SecondStage ofElections theWinner is determined by  theSame principle over theCities theWinner of  theElections is theCandidate who woninch  theMaximum Number  ofCities and amongThose who got theMaximum Number  ofCities theWinner is the  One  with aSmaller index. Determine who'll win theElections. Inputthe First  Line  of  theInputcontains  Bothintegers n, m (1? ≤?n,?m?≤? -) — the  Number  ofCandidates and  ofCities, respectively. each of  theNext mLines containsn non-negative integers, theJ-th Number inch  theI-th LineAIJ (1? ≤?j?≤?n,1? ≤?i?≤?m,0? ≤?aij?≤?109) denotes the  Number  ofVotes forCandidate JinchCity i.it are guaranteed that theTotal Number  ofPeopleinchAll theCities does notExceed109.OutputprintaSingle Number— theIndex of  theCandidate who won theElections. The candidates is indexed starting from  One.

Test instructions
Given n rows m column, the number of votes on behalf of the first city of the players of J Data[i][j], the election is divided into two times, for the first time, each city to elect the city of the highest ticket player to become the winner, if the number of votes, the election of the smallest, and then the second round, Select the players who have the most victories in each city as the final winner, if the number is the same, the number is the smallest.

Directly on the code:

/*date:2015-8-26 Night Author:itakmotto: Today I want to go beyond yesterday's me, tomorrow I will surpass today's me, to create better code as the goal, constantly surpass oneself. */#include <iostream>#include <cstring>using namespace STD;intdata[ the][ the];intans[ the];intMain () {intM, N, J, I, Ind; while(Cin>>m>>n) {memset(ANS,0,sizeof(ans)); for(i=0; i<n; i++) {intMax =-999; for(j=0; j<m; J + +) {Cin>>data[i][j];if(Data[i][j] > Max)                     {Max = data[i][j];                IND = j;        }} ans[ind]++; }intMax =-9999; for(i=0; i<m; i++)if(Ans[i] > Max)                {Max = ans[i];            IND = i; }cout<<ind+1<<endl; }return 0;}/**INPUT3 2 3 2 1output2input3 410 1 2 7output1**/ 5

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codeforces 570 A. Elections

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.