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

Java

Posted by Xi_Jinping at 2014-03-26 23:50:59 on Problem 3370
import java.io.*;

public class Main
{
	static int [] a = new int [100010],p = new int [100010];
	public static void main(String[] args) throws IOException
	{
		StreamTokenizer input = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
		PrintWriter output = new PrintWriter(new OutputStreamWriter(System.out));
		int c,n,i,sum,l,r = 0;
		while(input.nextToken() != StreamTokenizer.TT_EOF){
			c = (int)input.nval;
			input.nextToken();
			n = (int)input.nval;
			if(c == 0 && n == 0)break;
			for(i = 1;i <= n;++i){
				input.nextToken();
				a[i] = (int)input.nval;
				p[i] = 0;
			}
			sum = 0;
			for(l = i = 1;i <= n;++i){
				sum = (sum + a[i]) % c;
				if(sum == 0){
					r = i;
					break;
				}
				else if(p[sum] > 0){
					l = p[sum] + 1;
					r = i;
					break;
				}
				else p[sum] = i;
			}
			for(i = l;i < r;++i)
				output.print(i + " ");
			output.println(r);
		}
		output.flush();
	}
}

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