UVALive 2318 水题

时间:2023-03-08 20:43:07

给出c 个竞争者.v 个投票人。每个投票人的投票顺序。问你谁会胜出。在第几轮。完全是个水题。比赛的时候debug接近两个点没过。因此差点放弃了整场比赛。猜测是错在找最大和第二大的序号哪里错的。因为我换了一种方法就AC了。

以后该尝试着删掉debug不过的代码。重写。最近比赛总是被虐成狗、不知道是不是被失望了、或者。

好好努力吧。只是希望自己每次都能有所进步就好了。总是行走在路上。其实很难。

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std; int t;
int rankk[][];
int vote[], vote2[];
int num[]; int main()
{
int t;
int c, v;
cin >> t;
while(t--)
{
cin >> c >> v;
for (int i=; i<v; ++i)
{
for (int j=; j<c; ++j)
cin >> rankk[i][j];
}
int max1 = , max2 = ;
memset(vote, , sizeof(vote));
for (int i=; i<v; ++i)
{
int temp = rankk[i][];
vote[temp]++;
}
for (int i=; i<=c; ++i)
{
vote2[i]= vote[i];
}
sort(vote2+, vote2+c+);
max1 = vote2[c];
max2 = vote2[c-];
int cnt = ;
int max2_id;
for (int i=; i<=c; ++i)
{
if (vote[i] == max1)
{
num[] = i;
break;
}
}
for (int i=; i<=c; ++i)
{
if (vote[i] == max2 && i!=num[])
{
num[] = i;
break;
}
} if (max1 > v/)
{
cout << num[] << ' ' << << endl;
continue;
}
else
{
int num1 = num[], num2 = num[];
memset(vote, , sizeof(vote));
for (int i=; i<v; ++i)
{
for (int j=; j<c; ++j)
{
int temp = rankk[i][j];
if (temp == num1 || temp == num2)
{
vote[temp]++;
break;
}
}
}
if (vote[num1] > vote[num2])
{
cout << num1 << ' ' << << endl;
continue;
}
else
{
cout << num2 << ' ' << << endl;
continue;
}
}
}
return ;
}

LOoK