Fork me on GitHub

NYOJ题目64鸡兔同笼

--------------------------

 

经典水题,我第一次做这种题的时候完全懵逼用蛮力碰....

然而现在我终于学会列方程了....

 

 

解此方程:

 

排除掉小数和负数,得到的就是解。

 

AC代码:

 1 import java.util.Scanner;
 2 
 3 public class Main {
 4 
 5     public static void main(String[] args) {
 6         
 7         Scanner sc=new Scanner(System.in);
 8         
 9         int times=sc.nextInt();
10         while(times-->0){
11             int n=sc.nextInt();
12             int m=sc.nextInt();
13             if(m-2*n<0 || (m-2*n)%2!=0){
14                 System.out.println("No answer");
15             }else{
16                 int y=(m-2*n)/2;
17                 int x=n-(int)y;
18                 System.out.println(x+" "+(int)y);
19             }
20         }
21         
22     }
23     
24 }

 

题目来源: http://acm.nyist.net/JudgeOnline/problem.php?pid=64

posted @ 2016-09-21 00:14  CC11001100  阅读(239)  评论(0编辑  收藏  举报