随笔 - 9, 文章 - 0, 评论 - 1, 引用 - 0
数据加载中……

PKU 3740 Easy Finding

http://acm.pku.edu.cn/JudgeOnline/problem?id=3740

按照题目条件暴力枚举.
复杂度: O(2NM)
/**
 * 
@version 2009/08/28
 * 
@author sbzlyessit
 
*/

import java.io.*;
import java.util.*;

public class Main {

    
private static BufferedReader   in =
            
new BufferedReader(new InputStreamReader(System.in));
    
private static StringTokenizer  st;
    
private static int[]            matrix = new int[300];

    
public static void main(String[] argv) throws Exception {
        
int     N, M;
        
int     i, j, x;
        
boolean found;
        
while (in.ready()) {
            N 
= nextInt();
            M 
= nextInt();
            Arrays.fill(matrix, 
0);
            
for (i = 0; i < N; i++)
                
for (j = 0; j < M; j++)
                    
if (nextInt() == 1)
                        matrix[j] 
|= 1 << i;
            
for (found = false, i = (1 << N) - 1!found && i >= 0; i--) {
                
for (j = 0; j < M; j++) {
                    x 
= i & matrix[j];
                    
if (x == 0 || x - (x & (-x)) != 0break;
                }
                
if (j == M) {
                    found 
= true;
                    System.out.println(
"Yes, I found it");
                }
            }
            
if (!found) System.out.println("It is impossible");
        }
    }

    
private static int nextInt() throws Exception {
        
while (st == null || !st.hasMoreTokens())
            st 
= new StringTokenizer(in.readLine());
        
return Integer.parseInt(st.nextToken());
    }

}


posted on 2009-08-28 20:55 yessit 阅读(410) 评论(1)  编辑  收藏 所属分类: PKU

评论

# re: PKU 3740 Easy Finding[未登录]  回复  更多评论   

thank you very much
2009-10-13 20:49 | frank

只有注册用户登录后才能发表评论。


网站导航: