首页 > 代码库 > NYOJ题目64鸡兔同笼
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
NYOJ题目64鸡兔同笼
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。