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

总是WA:不行了,,帮忙看下把!

Posted by huangtianzhu5746 at 2007-09-11 22:20:36 on Problem 1745
import java.io.*;
import java.util.*;
public class Main {

	int[] num;
	int n;
	int k;
	String div = "Not divisible";
	public Main(int[] x, int y, int z) {
		num = x;
		n = y;
		k = z;
	}

	public void p(int index,int value) {
		
		for(int i=0;i<2;i++)
		{
			if(i==0&&div.equals("Not divisible"))
			{	
				if(index >= n-1) {
					if(value%k==0) {
						div ="Divisible";
						//System.out.println(value);
					}
					return ;
				}
				else p(index+1,value + num[index+1]);
			}
			if(i==1&&div.equals("Not divisible"))
			{
				if(index >= n-1) {
					if(value%k==0) {
						div ="Divisible";
					//	System.out.println(value);
						}
					return ;
				}
				else p(index+1,value - num[index+1]);
			}
		}
	}
	public static void main(String arg[]) throws Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine();
		StringTokenizer st = new StringTokenizer(s);
		int n = Integer.parseInt(st.nextToken());
		
		if(n<=0)
		{
			System.out.println("Not divisible");
			return;
		}
		int k =0;
		if(k==0)
		{
			System.out.println("Not divisible");
			return;
		}
		k = Integer.parseInt(st.nextToken());
		s= br.readLine();
		st = new StringTokenizer(s);
		int[] num = new int[n];
		int i = 0;
		while(st.hasMoreTokens())
		{
			num[i] = Integer.parseInt(st.nextToken());
			i++;
		}
		//System.out.println(num[n-1]);
		Main m = new Main(num, n ,k);
		m.p(0, num[0]);
		
		System.out.println(m.div);
	}
}

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