ACdream群OJ--1035

An Unfair Game

Time Limit: 6000/3000 MS (Java/Others)  Memory Limit: 128000/64000 KB (Java/Others)
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

/****************************
* author:crazy_石头
* date:2014/04/30
* time: 2888 ms
* algorithm:dfs
* Pro:UVA 
***************************/
#include 
   
   
    
    
#include 
    
    
     
     
#include 
     
     
      
      
#include 
      
      
       
       
#include 
       
       
         #include 
        
          #include 
         
           #include 
          
            #include 
           
             using namespace std; #define INF INT_MAX #define eps 1e-8 #define A system("pause") #define rep(i,h,n) for(int i=(h);i<=(n);i++) #define ms(a,b) memset((a),(b),sizeof(a)) #define lson l , m , rt << 1 #define rson m + 1 , r , rt << 1 | 1 #define LL long long const int N=100+5; const int maxm=30; int map[N][N],new_map[N][N],v[N],l[N],n,m; inline int dfs(int p) { rep(i,0,n-1) if (new_map[p][i]&&!v[i]) { v[i]=1; if (l[i]==-1 ||dfs(l[i])) { l[i]=p; return 1; } } return 0; } inline int fuck() { int ans=0; ms(l,-1); rep(i,0,n-1) if (i!=m) { ms(v,0); if (!dfs(i)) return 0; } return 1; } int main() { while (cin>>n) { int flag=1; rep(i,0,n-1) rep(j,0,n-1) cin>>map[i][j]; cin>>m; m--; rep(i,0,n-1) { rep(k,0,n-1) rep(j,0,n-1) if (k!=m && j!=i && map[k][j] 
            
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值