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 hudi112 at 2008-10-06 19:46:08 on Problem 1061
import java.io.*;
class Main
{
  void init() throws Exception
  {
    //BufferedReader br=new BufferedReader(new FileReader("frogappointment.txt"));
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    String[] number=br.readLine().split(" ");
    br.close();
    if (number[2].equals(number[3])) System.out.print("Impossible");
    else find(Integer.parseInt(number[0]),Integer.parseInt(number[1]),Integer.parseInt

(number[2]),Integer.parseInt(number[3]),Integer.parseInt(number[4]));
  }
  void find(int x,int y,int m,int n,int l) throws Exception
  {
    int k=1;
    int t=-1;
    int a=Math.abs(m-n);
    int b=0-Math.abs(y-x);
    if ((m>n && x<y) || (m<n && x>y))
    {
      k=0;b=Math.abs(b);
    }
    if ((b+l*k)%a==0) t=(b+l*k)/a;
    else
    {
      int q=(b+l*k)%a;
      int qq=l%a;
      if (qq!=0)
      {
        if (q%qq==0) t=(b+l*k)/a+(l/a)*(q/qq);
      }
    }
    if (t<0) System.out.print("Impossible");
    else show(t);
  }
  void show(int t) throws Exception
  {
    System.out.print(t);
  }
  public static void main(String[] args) throws Exception
  {
    Main m=new Main();
    m.init();
  }
}

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