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

re死我了

Posted by wpt at 2007-07-15 14:26:47 on Problem 1840
为什么。。。
import java.util.*;
import java.io.*;

public class Main{
    public static void main(String[] args) throws IOException {
        Scanner in=new Scanner(System.in);
        int[] pow=new int[101];
        for (int i=-50;i<51;i++)
        	pow[i+50]=i*i*i;
        int[] a=new int[5];
        for(int i=0;i<5;i++)
    	{
    		a[i]=in.nextInt();
    		if(a[i]<0)
    			a[i]*=-1;
    	}
       
    	Arrays.sort(a);
        int[] val1=new int[500002];
        int[] val2=new int[5002];
        int n1=0,n2=0,z1=0,z2=0;
        for (int i=-50;i<=50;i++)
        {
            if (i==0)
            	i=1;
            for (int j=-50;j<=50;j++)
            {
                if(j==0)
                	j=1;
                int t=a[0]*pow[i+50]+a[1]*pow[j+50];
                if(t==0)
                	z1++;
                else
                	if(t>0)
                		val2[n2++]=t;
            }
        }
        Arrays.sort(val2,0,n2);
        int max=val2[n2-1]+1,min=val2[0]-1;
        for (int i=-50;i<=50;i++)
        {
            if (i==0)
            	i=1;
            for (int j=-50;j<=50;j++)
            {
            	if(j==0)
                	j=1;
            	for(int k=-50;k<=50;k++)
            		if(k!=0)
            		{
            			int t=a[2]*pow[i+50]+a[3]*pow[j+50]+a[4]*pow[k+50];
            			if(t==0)
            				z2++;
            			else
            				if(t>min&&t<max)
            					val1[n1++]=t;
            		}
            }
        }
        Arrays.sort(val1,0,n1);
        int t1=0,t2=0,c=0;
        while(true)
        {
        	while(t2<n2&&val1[t1]>val2[t2])
        		t2++;
        	while(t1<n1&&val1[t1]<val2[t2])
        		t1++;
        	if(t1>=n1||t2>=n2)
        		break;
        	else
        		if(val1[t1]==val2[t2])
            	{
            		int c1=1,c2=1;
            		t1++;
            		t2++;
            		while(t1<n1&&val1[t1-1]==val1[t1])
            		{
            			t1++;
            			c1++;
            		}
            		while(t2<n2&&val2[t2-1]==val2[t2])
            		{
            			t2++;
            			c2++;
            		}
            		c+=c1*c2;
            	}
        }
        System.out.println(c*2+z1*z2);  
  
    }
}

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