Elections
题目链接:
http://codeforces.com/problemset/problem/570/A
解题思路:
We need to determine choice for each city. Then sum it for each candidate and determine the winner.
O(n * m)
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int num[110];
int main(){
int n,m;
while(~scanf("%d%d",&n,&m)){
memset(num,0,sizeof(num));
int sum,tmp,x;
for(int i = 1; i <= m; i++){
sum = 0;tmp = 1;
for(int j = 1; j <= n; j++){
scanf("%d",&x);
if(sum < x){
tmp = j;
sum = x;
}
}
num[tmp]++;
}
sum = 0;tmp = 1;
for(int i = 1; i <= n; i++){
if(sum < num[i]){
sum = num[i];
tmp = i;
}
}
printf("%d\n",tmp);
}
return 0;
}
Codeforces选举问题解析
本文介绍了一个关于选举的问题,该问题出自Codeforces平台,并提供了一种有效的解决方案。通过遍历每个城市的选择,累加每位候选人的得票数,最终确定获胜者。此算法的时间复杂度为O(n*m),其中n代表城市数量,m代表候选人数量。
631

被折叠的 条评论
为什么被折叠?



