题意:澳大利亚投票系统要求选民们将全部候选人按愿意选择的程度排序,一张选票就是一个排序。一開始,每张选票的首选项将被统计。若有候选人得票超过50%,他讲直接胜出;否则,全部并列最低的候选人出局,而那些将出局候选人排在第一位的选票将被又一次统计为排名最高的未出局候选人。这一筛选过程将持续进行,直到某个候选人得到超过50%的选票,或全部候选人得票同样。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const int N = 50;
#define INF 0x3fffffff
int vote[1050][N];
int out[N], cnt[N];
char name[N][100];
int num;
int main()
{
int T, n, i, j;
char str[1000];
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
getchar();
for(i = 1; i <= n; i++)
gets(name[i]);
num = 0;
while(gets(str) != NULL)
{
if(!strcmp(str, "")) break;
int len = strlen(str);
int s = 0, k = 0;
for(i = 0; i < len; i++)
{
if(str[i] >= '0' && str[i] <= '9')
s = s * 10 + str[i] - '0';
else
{
vote[num][k++] = s;
s = 0;
}
}
vote[num][k++] = s;
num++;
}
memset(out, 0, sizeof(out));
int flag = 0, rest = n, total = 0;
while(rest > 1) //未出局候选人数超过1
{
total = 0; //总票数
memset(cnt, 0, sizeof(cnt));
for(i = 0; i < num; i++)
{
for(j = 0; j < n; j++)
{
if(!out[vote[i][j]])
{
cnt[vote[i][j]]++;
total++;
break;
}
}
}
for(i = 1; i <= n; i++)
if(cnt[i] * 2 > total && !out[i])
{
printf("%s\n",name[i]);
flag = 1;
break;
}
if(flag) break;
int mmin = INF, mmax = 0;
for(i = 1; i <= n; i++)
{
if(!out[i])
{
mmin = min(mmin, cnt[i]);
mmax = max(mmax, cnt[i]);
}
}
if(mmin == mmax)
break;
for(i = 1; i <= n; i++)
if(cnt[i] == mmin)
{
out[i] = 1;
rest--;
}
}
if(!flag)
{
for(i = 1; i <= n; i++)
if(!out[i])
printf("%s\n", name[i]);
}
if(T > 0)
printf("\n");
}
return 0;
}

UVA 10142 Australian Voting(模拟)的更多相关文章

  1. Uva 10142 Australia Voting

    水题 模拟 大意就是模拟一个选举的系统 认真读题,注意细节,耐心调试 #include<cmath> #include<math.h> #include<ctype.h& ...

  2. UVa 11210 - Chinese Mahjong 模拟, 枚举 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  3. UVA 1156 - Pixel Shuffle(模拟+置换)

    UVA 1156 - Pixel Shuffle 题目链接 题意:依据题目中的变换方式,给定一串变换方式,问须要运行几次才干回复原图像 思路:这题恶心的一比,先模拟求出一次变换后的相应的矩阵,然后对该 ...

  4. UVA 12050 - Palindrome Numbers 模拟

    题目大意:给出i,输出第i个镜像数,不能有前导0. 题解:从外层开始模拟 #include <stdio.h> int p(int x) { int sum, i; ;i<=x;i+ ...

  5. Uva 679 Dropping Balls (模拟/二叉树的编号)

    题意:有一颗二叉树,深度为D,所有节点从上到下从左到右编号为1,2,3.....在结点一处放一个小球,每个节点是一个开关,初始全是关闭的,小球从顶点落下,小球每次经过开关就会把它的状态置反,现在问第k ...

  6. ●UVa 1589 Xiangqi(模拟)

    ●赘述题意 给出一个中国象棋残局,告诉各个棋子的位置,黑方只有1枚“将”,红方有至少2枚,至多7枚棋子,包含1枚“帅G”,和若干枚“车R”,“马H”,“炮C”.当前为黑方的回合,问黑方的“将”能否在移 ...

  7. 【每日一题】 UVA - 213 Message Decoding 模拟解码+读入函数+阅读题

    题意:阅读理解难度一道比一道难orz.手摸了好久样例 题解: 读入:大循环用getline读入header顺便处理一下,  里面再写两重循环,外层一次读三个串,内层一次读num个串. 之后就查表,线性 ...

  8. Codeforces 749C. Voting 模拟题

    C. Voting time limit per test: 1 second memory limit per test: 256 megabytes input: standard input o ...

  9. 【紫书】【重要】Abbott's Revenge UVA - 816 bfs 复杂模拟 带方向参数的迷宫

    题意:一个迷宫,每个交叉路口有一路标,限制了你从某方向进入该路口所能进入的路口. 题解:1.对于方向的处理:将node多增加一维dir,通过一个const 字符数组 加 上dir_id函数 以及一个方 ...

随机推荐

  1. nginx的反向代理和负载均衡的区别是什么 - 开源中国社区

    nginx的反向代理和负载均衡的区别是什么 - 开源中国社区   nginx的反向代理和负载均衡的区别是什么 #user  nobody;worker_processes  1;#error_log  ...

  2. Android菜鸟的成长笔记(4)——你真的理解了吗?

    原文:Android菜鸟的成长笔记(4)--你真的理解了吗? 在上一篇中我们查看了QQ的apk源文件中的布局结构,并仿照QQ完成了我们第一个应用的界面,详细请看<Android菜鸟的成长笔记&g ...

  3. HDU4869:Turn the pokers(费马小定理+高速幂)

    Problem Description During summer vacation,Alice stay at home for a long time, with nothing to do. S ...

  4. Swift - 自定义函数规则说明

    1,无返回值的函数 1 2 3 func test(name:String){   } 2,返回一个返回值 1 2 3 func test(name:String) -> Bool{     r ...

  5. Ubuntu下实现双屏独立切换

    在编码时,总觉得屏幕大小不够,要是能多个屏多好,可以这样 把你的显示器连接到你的电脑,然后开启一个终端 输入:xrandr 显示如下: LVDS1 connected 1366x768+1024+0 ...

  6. 基于Qt的类QQ气泡聊天的界面开发

    近期在写IM 聊天界面,想设计出一个类似QQ气泡聊天的样式 使用了几种办法 1:使用Qt以下的QListview来实现QQ类似效果.差强人意 2:使用QWebview载入html css样式来完毕.发 ...

  7. counting objects in class

    參考文献:pgno=1">http://www.drdobbs.com/cpp/counting-objects-in-c/184403484? pgno=1

  8. STM32M CUBE实现printf打印调试信息以及实现单字节接收

    在写单片机程序时我们一般喜欢使用printf来通过串口打印调试信息,但这个函数是不能够直接使用的.必须做点对库函数的修改. 具体project下载地址: http://download.csdn.ne ...

  9. FreeSwitch安装和配置记录

    安装FreeSwitch 主要示例,下面的命令: git clone -b v1.2.stable git://git.freeswitch.org/freeswitch.git cd freeswi ...

  10. 【UVA】10012 - How Big Is It?(暴力)

    使用DFS枚举所有的安排.每次加入后,当一个圆.他的立场是最大的,并已加入了圆环中的所有切线位置前面. 14383635 10012 option=com_onlinejudge&Itemid ...