Problem Description

There are n people and n target, everyone should get one target, no two people get the same target, the last one who get the target should be punished, there is only one person will be punished, so if more than one person are the last, no one will be punished. As the judge, you know exactly how much time that people i getting target j will spend, but there are no people know how much time he needs. You need to arrange for a target to everyone, and you want the i-th people to be punished (Now you know why it is an unfair game?).

Input

The input contains several test, and ends with EOF. For each test, the first line has an integer n,which is the number of people and target,next there is an integer matrix which size is n*n, the i-th row and the j-th colume of matrix means the time that i-th person needs to get target j. Next line is a number m, the number of the person who you want to be punished.

1<=m<n<=100

Output

 Each test print one line, the number of the target that m-th person gets, if there are more than one answer, print all of them. If there is no answer, only print -1.

Sample Input

3
1 2 3
2 3 4
3 4 5
3
3
3 3 3
2 2 2
1 1 1
3

Sample Output

2 3
-1

Source

UUZ

Manager

题目大概意思是有N个人选择N个目标每人1个.第i个人选择第j个目标花费d[i][j]的时间.用时最长的选手受到惩罚.现在希望通过决定各个选手选择的目标使第M个选手受到惩罚,求此时M选手选择的目标.
一开始我居然觉得是贪心什么什么的...真是手生了.后来发现这是一道二分图匹配的问题.首先尝试i=1~N的点与M结合.与此同时删除M点与i点和其他点之间的连线.再删除花费时间超过d[M][i]的点.对剩下的图求最大匹配.如果结果是N-1则可以使M选手受到惩罚.
 #include<stdio.h>
#include<string.h>
int d[][],res[],N,M,q[];
bool f[][],sta[];
bool find(int a)
{
for (int i=;i<=N;i++)
{
if (f[a][i] && (!sta[i]))
{
sta[i]=true;
if (res[i]== || find(res[i]))
{
res[i]=a;
return true;
}
}
}
return false;
}
int hungary()
{
memset(res,,sizeof(res));
int Ans=;
for (int i=;i<=N;i++)
{
memset(sta,,sizeof(sta));
if (find(i)) Ans++;
}
return Ans;
}
int main()
{
while (scanf("%d",&N)!=EOF)
{
for (int i=;i<=N;i++)
for (int j=;j<=N;j++)
scanf("%d",&d[i][j]);
scanf("%d",&M);
int T=;
for (int i=;i<=N;i++)
{
memset(f,true,sizeof(f));
for (int j=;j<=N;j++) f[j][i]=false;
for (int j=;j<=N;j++) f[M][j]=false;
for (int j=;j<=N;j++)
for (int k=;k<=N;k++)
if (d[j][k]>=d[M][i]) f[j][k]=false;
if (hungary()==(N-)) q[++T]=i;
}
if (T==) printf("-1\n");
else
{
for (int i=;i<T;i++) printf("%d ",q[i]);
printf("%d\n",q[T]);
}
}
return ;
}

An Unfair Game-[ACdream1035]的更多相关文章

  1. Codeforces758C Unfair Poll 2017-01-20 10:24 95人阅读 评论(0) 收藏

    C. Unfair Poll time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. 【找规律】Codeforces Round #392 (Div. 2) C. Unfair Poll

    C. Unfair Poll time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  3. Codeforces Round #392 (Div. 2) Unfair Poll

    C. Unfair Poll time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. CodeForces 758 C Unfair Poll

    Unfair Poll 题意:一共有n排同学每排同学有m个人, 老师问问题有一个顺序, 先从第一排开始问,问完第一排的所有同学之后,再问第2排的,对于所有排的访问顺序为 1,2,3……n-1,n,n- ...

  5. C. Unfair Poll

    http://codeforces.com/problemset/problem/758/C C. Unfair Poll time limit per test 1 second memory li ...

  6. 【HDOJ】4317 Unfair Nim

    基本的状态压缩,想明白怎么dp还是挺简单的.显然对n个数字进行状态压缩,dp[i][j]表示第i位状态j表示的位向高位产生了进位. /* 4317 */ #include <iostream&g ...

  7. CF758C Unfair Poll

    题意: On the Literature lesson Sergei noticed an awful injustice, it seems that some students are aske ...

  8. C. Unfair Poll 数学题,

    http://codeforces.com/contest/758/problem/C 需要一个能够找到任意一个位置的步数的方法,就能解决三个问题. 预处理出one(row, col)表示第一次经过这 ...

  9. 【codeforces 758C】Unfair Poll

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. Java使用正则表达式解析LRC歌词文件

    LRC歌词是一种应用广泛的歌词文件,各主流播放器都支持. lrc歌词文本中含有两类标签: 1.标识标签(ID-tags) [ar:艺人名] [ti:曲名] [al:专辑名] [by:编者(指编辑LRC ...

  2. python如何一行输入多个值

    python2的raw_input以及python3的input获取的是整行的字符串.读进来后,字符串有着著名的split可以根据分隔符拆解成子串组成的list. 对于list内的对象,需要的采取转换 ...

  3. Mac系统下使用VirtualBox虚拟机安装win7--第五步 共享文件夹设置

    1.启动virtualbox--选中win7虚拟机--点击设置--点击共享文件夹--点击右侧按钮添加共享文件夹

  4. js获取缓存数据

    后台:request.setAttribute("type", type); 前台js获取:var type = "${type}";

  5. 【mysql创建用户|删除用户|修改用户权限|常用命令】

    原文链接:http://blog.csdn.net/leili0806/article/details/8573636 1.       CREATE USER 语法: CREATE USER 'us ...

  6. .net socket 层面实现代理服务器

    socket 层面实现代理服务器 首先是简一个简单的socket客户端和服务器端的例子 建立连接 Socket client = new Socket(AddressFamily.InterNetwo ...

  7. js特效

    1.轮播换图 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  8. PowerDesigner(PowerDesigner15.1.0.2850)下载、安装以及破解

    转自:http://www.cnblogs.com/Fonkie/articles/1600662.html 一.先安装PowerDesigner15(PowerDesigner15.1.0.2850 ...

  9. 在ubuntu中安装jdk

    安装环境 操作系统:ubuntu 14.04.1 server amd64 下载jdk wget http://download.oracle.com/otn-pub/java/jdk/7u67-b0 ...

  10. HDU 3364 Lanterns 高斯消元

    Lanterns Problem Description   Alice has received a beautiful present from Bob. The present contains ...