close

題目概要:

計算出2對目前比分。s為兩隊比分相加,d為兩隊比分相減。

解題方向:

二元方程式概念下去解即可。

程式碼:

//Java
import java.util.Scanner;
class uva10812{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int cases=sc.nextInt();
for(int i=0;i<cases;i++){
long s=sc.nextLong(),d=sc.nextLong();
long x=s+d,y=s-d;
//Output
if(x<0 || y<0 || (x%2!=0 || y%2!=0)) System.out.println("impossible"); //比數<0 或者 比數不能整除 皆為不可能出現。
else System.out.println(x/2+" "+y/2);
}
}
}
view raw uva10812.java hosted with ❤ by GitHub

arrow
arrow
    文章標籤
    Java
    全站熱搜
    創作者介紹
    創作者 a7069810 的頭像
    a7069810

    紀錄自己的程式人生

    a7069810 發表在 痞客邦 留言(0) 人氣()