题意:澳大利亚投票系统要求选民们将全部候选人按愿意选择的程度排序,一张选票就是一个排序。一開始,每张选票的首选项将被统计。若有候选人得票超过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. NFS服务器端配置

    服务器端配置1 创建共享目录# mkdir /home/share# chown nobody.nogroup /home/share2 创建或修改/etc/exports 配置文件这个文件的内容非常 ...

  2. JSTL解析——004——core标签库03

    上面章节主要讲解<c:forEach>标签,下面讲解其它标签 1.<c:forTokens>标签 forTokens标签与forEach标签类似,独有begin.end.ste ...

  3. 在gfs2中关闭selinux

    在构建iSCSI存储集群时,请勿在gfs2中使用selinux

  4. Swift - 类和结构体的区别

    类和结构体有许多相同之处,也有许多不同之处. 二者区别如下: 1,类可以继承和扩展,结构体不可以 2,可以让一个类的实例来反初始化,释放存储空间,结构体做不到 3,类的对象是引用类型,而结构体是值类型 ...

  5. c# listview导出excel文件

    首先在工程中需要添加对Microsoft Excel office 11.0 object的引用 生成excel的类代码如下 using System; using System.Collection ...

  6. 深入认识Tigase XMPP Server(上)

    深入认识Tigase XMPP Server(上) 作者:chszs,转载需注明.博客主页:http://blog.csdn.net/chszs 本文的目的是深入认识Tigase XMPP Serve ...

  7. POJ2828 Buy Tickets 【线段树】+【单点更新】+【逆序】

    Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 12296   Accepted: 6071 Desc ...

  8. 解决org.hibernate.LazyInitializationException: could not initialize proxy - no Session懒载入问题

    问题描写叙述: Struts Problem Report Struts has detected an unhandled exception: Messages: could not initia ...

  9. Nagios的客户端的安装

    一.Linux服务器的nagios客户端的安装 步骤: 1.  创建目录,上传文件到该目录 mkdir /data nagios-plugins-2.1.1.tar.gz nrpe-2.12.tar. ...

  10. (1)cocos2d-x-2.2.4搭建windows开发环境

    Cocos2d-x-2.2.4搭建windows环境 软件需求 Windows系统(windows7或之后的系统): cocos2d-x-2.2.4压缩包. python安装包(推荐使用2.7.3版本 ...