An Unfair Game-[ACdream1035]
Problem Description
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
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
Manager
#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]的更多相关文章
- 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 ...
- 【找规律】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 ...
- 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 ...
- CodeForces 758 C Unfair Poll
Unfair Poll 题意:一共有n排同学每排同学有m个人, 老师问问题有一个顺序, 先从第一排开始问,问完第一排的所有同学之后,再问第2排的,对于所有排的访问顺序为 1,2,3……n-1,n,n- ...
- C. Unfair Poll
http://codeforces.com/problemset/problem/758/C C. Unfair Poll time limit per test 1 second memory li ...
- 【HDOJ】4317 Unfair Nim
基本的状态压缩,想明白怎么dp还是挺简单的.显然对n个数字进行状态压缩,dp[i][j]表示第i位状态j表示的位向高位产生了进位. /* 4317 */ #include <iostream&g ...
- CF758C Unfair Poll
题意: On the Literature lesson Sergei noticed an awful injustice, it seems that some students are aske ...
- C. Unfair Poll 数学题,
http://codeforces.com/contest/758/problem/C 需要一个能够找到任意一个位置的步数的方法,就能解决三个问题. 预处理出one(row, col)表示第一次经过这 ...
- 【codeforces 758C】Unfair Poll
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- iPhone:4.7 5.5 4 3.5 对应的各个设备屏幕尺寸对应的像素及App上线信息
Shared App Information You can access these properties from the App Details page in the App Informat ...
- elipse插件整理
整理一下用过的eclipse插件: 1. WindowBuilder :swing插件,可以拖啊拖啊拖出来一个窗口,可以显著提高开发效率. 官网: http://www.eclipse.org/w ...
- NYOJ题目34韩信点兵
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAskAAAHiCAIAAACV1MbSAAAgAElEQVR4nO3dPXLjONeG4W8TyrUQx1 ...
- JavaScript基础——使用运算符
JavaScript运算符允许你改变一个变量的值.你已经熟悉了用于赋值给变量的=运算符.JavaScript提供了几种不同的运算符,它们可以划分为两大类:算数运算符和赋值运算符. 1.算数运算符 你可 ...
- iOS - 线程管理
iOS开发多线程篇—GCD的常见用法 一.延迟执行 1.介绍 iOS常见的延时执行有2种方式 (1)调用NSObject的方法 [self performSelector:@selector(run) ...
- CLR via C#(09)-扩展方法
对于一些现成的类,如果我们想添加一些新的方法来完善功能,但是不想改变已有的封装,也不想使用派生类,那么该怎么办呢?这里我们可以使用扩展方法. 一见钟情--初识扩展 扩展方法使您能够向现有类型“添加”方 ...
- 自动复制转换StringBuffer
自动复制转换StringBuffer http://www.cnblogs.com/coqn/archive/2012/07/31/all_StringBuufer.html http://blog. ...
- C语言中do...while(0)的妙用
在linux内核代码中,经常看到do...while(0)的宏,do...while(0)有很多作用,下面举出几个: 1.避免goto语句: 通常,如果一个函数开始要分配一些资源,然后如果在中途遇到错 ...
- 【leetcode】plus One
问题描述: Given a non-negative number represented as an array of digits, plus one to the number. The dig ...
- 如何在java程序中调用linux命令或者shell脚本
转自:http://blog.sina.com.cn/s/blog_6433391301019bpn.html 在java程序中如何调用linux的命令?如何调用shell脚本呢? 这里不得不提到ja ...