zoukankan      html  css  js  c++  java
  • 欧几里得算法——欧几里得游戏

    题目:一开始,板上写有两个不相等的正整数.两个玩家交替写数字,每一次,当前玩家都必须在板上写出任意两个板上数字的差,而且这个数字必须是新的(且为正),也就是说,不能与板上任何一个已有的数字相同.当玩家再也写不出新数字时,他就输了.请问,你是选择先行动还是后行动呢?

     1 import java.util.Scanner;
     2 
     3 /**
     4  * Created by Administrator on 14-7-16.
     5  */
     6 public class EuclidGame {
     7     public static void main(String[] args){
     8         int number=0;
     9         System.out.println("please give the number:");
    10         Scanner scanner=new Scanner(System.in);
    11         String str=scanner.nextLine();
    12         int a=Integer.parseInt(str);
    13         str=scanner.nextLine();
    14         int b=Integer.parseInt(str);
    15         winGame(gcd(a>b?a:b,a<=b?a:b),a>b?a:b);
    16     }
    17     public static int gcd(int a,int b){
    18         int r;
    19         while(b!=0){
    20             r=a;
    21             a=b;
    22             b=r%a;
    23         }
    24         return a;
    25     }
    26     public static void winGame(int number,int max){
    27         if((max/number)%2!=0){
    28             System.out.println("the first one wins!");
    29         }
    30         else {
    31             System.out.println("the second one wins");
    32         }
    33     }
    34 }
  • 相关阅读:
    百奥谷
    3月13日火箭VS老鹰
    百度 hi 下载地址(内测版,正式版)
    中兴u980
    2008年清明节放假通知
    cyp740703 一个女人的自白
    黄唇鱼
    3月9日火箭vs黄蜂
    3月3日火箭vs掘金
    百度hi邀请码
  • 原文地址:https://www.cnblogs.com/mingcaoyouxin/p/3849559.html
Copyright © 2011-2022 走看看