1.6.8 Australia votes Australian voting

Source: Internet
Author: User
Tags min printf

Pc/uva 110108/10142

Simulation.

AUTHOR:CHC//first Edit time:2014-01-14 14:37//last edit time:2014-01-15 22:03//filename:1.cpp #include <iostrea m> #include <cstdio> #include <string.h> #include <queue> #include <vector> #include <
Algorithm> using namespace std;
int N,t,ns;
Char s[30][100];
Char ts[1000];
Vector <int> vote[1010];
Vector <int>:: iterator it;
int ha[30];
    void getnum (int kn) {int i=0;
        while (Ts[i]) {while (ts[i]== ' &&ts[i]) i++;
        int tt=0;
            while (ts[i]!= ' &&ts[i]) {tt=tt*10+ts[i]-' 0 ';
        ++i;
    } if (tt!=0) Vote[kn].push_back (TT);
    }} void voted () {for (int i=0;i<ns;i++) {ha[vote[i][0]]++;
        } while (1) {int ping=1,min=1010,first=-1;
                for (int i=0;i<n;i++) {if (HA[I+1]&GT;NS/2) {printf ("%s\n", S[i]);
            return; }/* if (ha[i+1]>=0&&first==-1) FIRST=HA[I+1];
            if (First>=0&&ha[i+1]>=0&&ha[i+1]!=first) ping=0;
            if (ha[i+1]>=0&&ha[i+1]<min) min=ha[i+1];
                *////* if (ha[i+1]>=0) {if (min!=1010&&min!=ha[i+1]) ping=0;
            if (min>ha[i+1]) min=ha[i+1];
                    }//*/} if (ping) {for (int i=0;i<n;i++) if (ha[i+1]>=0)
            printf ("%s\n", S[i]);
        return;
            } for (int i=0;i<ns;i++) {int flag= (min==ha[vote[i][0]]);
                    For (It=vote[i].begin (); It!=vote[i].end (); it++) if (ha[*it]==min) {vote[i].erase (IT);
                it--;
        } if (flag) ha[vote[i][0]]++;
    } for (int i=0;i<n;i++) if (ha[i+1]==min) ha[i+1]=-1;
    }} int main () {scanf ("%d", &t);
        while (t--) {scanf ("%d", &n);

        GetChar ();
        for (int i=0;i<1010;i++) vote[i].clear ();

        memset (ha,0,sizeof (ha));
        for (int i=0;i<n;i++) {gets (s[i]);
        } ns=0;
            while (gets (TS)!=null&&strcmp (ts, "")!=0) {getnum (NS);
        ++ns;
        } voted ();
    if (t!=0) puts ("");
} return 0;
 }



Australian voting

Australian ballots require that voters rank all the candidates in order of choice. Initially only the first choices is counted, and if one candidate receives more than 50% of the vote then that candidate Is elected. However, if no candidate receives more than 50%, all candidates tied for the lowest number of votes is eliminated. Ballots ranking these candidates first is recounted in favor of their highest-ranked non-eliminated candidate. This process of eliminating the weakest candidates and counting their ballots in favor of the preferred non-eliminated can Didate continues until one candidate receives more than 50% of the vote, or until all remaining candidates is tied.

Input

The input begins with a single positive integer on a line by itself indicating the number of cases following, each as Desc Ribed below. This was followed by a blank line. There is also a blank line between the consecutive inputs.

The first line of all case are an integer N20 indicating the number of candidates. The next n lines consist of the names of the candidates in order, each up to a characters in length and containing any PR Intable characters. Up to $ lines follow, each containing the contents of a ballot. Each ballot contains the numbers from 1 to n in some order. The first number indicates the candidate of first choice; The second number indicates candidate of second choice, and so on.

Output

The output of each test case consists of either a single line containing the name of the winner or several lines Containin G The names of all candidates who is tied. The output of each of the consecutive cases is separated by a blank line.

Sample Input

1

3
John Doe
Jane Smith
Jane Austen
1 2 3
2 1 3
2 3 1
1 2 3
3 1 2

Sample Output

John Doe


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.