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 faen at 2005-05-11 22:09:33 on Problem 1063
小弟是在想不出这个在那里有错误了,wa好几次了。
import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String [] args)throws Exception
	{
		
		Scanner cin=new Scanner(System.in);
		int tt=cin.nextInt();
		while(tt--!=0)
		{
			int n=cin.nextInt();
			if(n%2!=0)
				System.out.println("YES");
			else
			{
				int a=0,b=0;
				int c=0,d=0;
				for(int i=0;i<n;i++)
				{
					int t=cin.nextInt();
					if(t==0)
					{
						if(i%2==0)a++;
						else b++;
					}
					else
					{
						if(i%2==0)
							c++;
						else
							d++;
					}	
				}
				if((a==b&&c==d)||(a-b==1&&d-c==1)||(a-b==-1&&c-d==1))
					System.out.println("YES");
				else
					System.out.println("NO");
			}
		}
	}

}

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