close
題目概要:
計算出2對目前比分。s為兩隊比分相加,d為兩隊比分相減。
解題方向:
二元方程式概念下去解即可。
程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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); | |
} | |
} | |
} |
文章標籤
全站熱搜