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. hadoop namenode ha--手动切换(转)

    1.hadoop的dfs.nameservices如何配置?2.集群配置中hdfs://mycluster的作用是什么?3.如何将namenode2切换为active状态? 在参考本手册前请确保Had ...

  2. bt和wifi的共存

    转自:http://bbs.52rd.com/Thread-291892-1-1.html 蓝牙和802.11b/g/n都可能工作在2.4GISM,可能互相干扰.干扰的典型应用之一是VOIP,用手机的 ...

  3. CI重定向:php(codeigniter)中如何重定向

    Q: 在保存完数据之后需要重定向,防止数据重复提交. 我使用$this->方法名();跳转,发现不能达到重定向的效果(地址栏没变) 请教高手重定向怎么用 A: $this->load-&g ...

  4. 【Python】 用python实现定时数据解析服务(前言)

    一.Why do it? 背景:项目里上传上来的数据都是未解析的数据,而且数据量还算挺庞大的,每天上传的数据有5kw左右,如果用数据库自带的作业来解析的话,数据库会造成严重的阻塞.因此打算把数据读到外 ...

  5. JVM_Bind:8080 的解决办法【131031】

    出错情况:运行 Tomcat 时报错 含义:8080 位置显示的端口被其他进程占用 解决方法: 方法1: 开始--运行--cmd 进入命令提示符 输入netstat -ano 即可看到所有连接的PID ...

  6. xml解析方法总结

    ==========================================xml文件<?xml version=”1.0″ encoding=”GB2312″?> <RES ...

  7. javascript实用技巧,js小知识

    一.js整数的操作 使用|0和~~可以将浮点转成整型且效率方面要比同类的parseInt,Math.round 要快,在处理像素及动画位移等效果的时候会很有用.性能比较见此. var foo = (1 ...

  8. Codeforces Round #363 LRU(概率 状压DP)

    状压DP: 先不考虑数量k, dp[i]表示状态为i的概率,状态转移方程为dp[i | (1 << j)] += dp[i],最后考虑k, 状态表示中1的数量为k的表示可行解. #incl ...

  9. phpcms v9网站搬家更换域名的方法

    PHPCMS 是国内领先的网站管理系统,同时也是一个开源的PHP开发框架. 本文介绍phpcms v9网站搬家更换域名的方法. 1.在新的主机空间把phpcms安装好. 新安装的版本一定要和准备搬迁的 ...

  10. hdu 4293 2012成都赛区网络赛 dp ****

    题意:有n个人,可任意分成若干组,然后每个人个各提供一个信息,表示他们组前面有多少人,后面有多少人.问最多有多少个信息是不冲突的. 将n个人看成一组区间,然后每个人的信息可以表示为该人所在组的区间,然 ...