Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

谁能帮我看看,谢谢了

Posted by wpt at 2007-03-28 14:21:10 on Problem 2893
import java.io.*;
import java.util.StringTokenizer;

public class MNproblem {
	static int[] num;
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	    String oneLine;
	    StringTokenizer str;
	    for(;;)
	    {
	    	oneLine=br.readLine();
	    	if(oneLine.equals("0 0"))
	    		return;
	    	str=new StringTokenizer(oneLine);
	    	int  m=Integer.parseInt(str.nextToken()),n=Integer.parseInt(str.nextToken());
	    	int[] num=new int[n*m];
	    	int t=0,ath=0,k=0;
	    	for(int i=0;i<m;i++)
	    	{
	    		str=new StringTokenizer(br.readLine());
	    		for(int j=0;j<n;j++)
	    			num[t++]=Integer.parseInt(str.nextToken());
	    	}
	    	for(int i=0;i<t;i++)
	    	{
	    		if(num[i]==0)
	    			k=m*n-1-i;
	    		for(int j=i+1;j<t;j++)
	    			if(num[j]<num[i])
	    				ath++;
	    	}
	    	if(((k&1)==0&&(ath&1)==((t-1)&1))||((k&1)==1&&(ath&1)!=((t-1)&1)))
	    		System.out.println("YES");
	    	else
	    		System.out.println("NO");
	    }
	}

}

对于n*m的矩阵(n行m列),两个格局可以互相转换当且仅当,将空格用0代替以后:
a. 若两格局中0的距离为偶数,两者的逆序数的奇偶性相同。
b. 若两格局中0的距离为奇数,两者的逆序数的奇偶性相异。
用来求逆序数的数字序列可以按矩阵先从左到右,然后从上至下得到。

用这个方法写得
哪有问题吗?

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator