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

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

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

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;

int t;
int rankk[210][210];
int vote[210], vote2[210];
int num[3];

int main()
{
    int t;
    int c, v;
    cin >> t;
    while(t--)
    {
        cin >> c >> v;
        for (int i=0; i<v; ++i)
        {
            for (int j=0; j<c; ++j)
                cin >> rankk[i][j];
        }
        int max1 = 0, max2 = 0;
        memset(vote, 0, sizeof(vote));
        for (int i=0; i<v; ++i)
        {
            int temp = rankk[i][0];
            vote[temp]++;
        }
        for (int i=1; i<=c; ++i)
        {
            vote2[i]= vote[i];
        }
        sort(vote2+1, vote2+c+1);
        max1 = vote2[c];
        max2 = vote2[c-1];
        int cnt = 0;
        int max2_id;
        for (int i=1; i<=c; ++i)
        {
            if (vote[i] == max1)
            {
               num[0] = i;
               break;
            }
        }
        for (int i=1; i<=c; ++i)
        {
            if (vote[i] == max2 && i!=num[0])
            {
                num[1] = i;
                break;
            }
        }

        if (max1 > v/2)
        {
            cout << num[0] << ' ' << 1 << endl;
            continue;
        }
        else
        {
            int num1 = num[0], num2 = num[1];
            memset(vote, 0, sizeof(vote));
            for (int i=0; i<v; ++i)
            {
                for (int j=0; j<c; ++j)
                {
                    int temp = rankk[i][j];
                    if (temp == num1 || temp == num2)
                    {
                        vote[temp]++;
                        break;
                    }
                }
            }
            if (vote[num1] > vote[num2])
            {
                cout << num1 << ' ' << 2 << endl;
                continue;
            }
            else
            {
                cout << num2 << ' ' << 2 << endl;
                continue;
            }
        }
    }
    return 0;
}
LOoK

 

posted on 2015-08-02 12:02  小小八  阅读(159)  评论(0编辑  收藏  举报