Stone game _ hdu_2516 (game rules). java

Source: Internet
Author: User

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission (s): 2228 Accepted Submission (s ): 1277 the Problem Description1 Heap has n stones, and the two take turns. the first accessors can fetch any number of entries for 1st times, but not all of them. in the future, the number of stones retrieved each time cannot exceed 2 times the number of stones obtained last time. Winner. the first accessor outputs "Second win ". the winner wins the output of "First win ". there are multiple Input groups. the 1st rows in each group are 2 <= n <2 ^ 31. n = 0 exit. the Output operator outputs "Second win ". the winner wins the output of "First win ". see Sample Output. sample input0000100000 Sample OutputSecond winSecond winFirst win SourceECJTU 2008 Autumn Contest Recommendlcy | We have carefully selected several similar problems for you: 2509 2512 1536 1907 1524

import java.io.InputStreamReader;  import java.util.Scanner;    public class Main{      public static void main(String[] args) {          Scanner input=new Scanner(new InputStreamReader(System.in));          int n;          while((n=input.nextInt())!=0){              if(n<4){                  System.out.println("Second win");                  continue;              }              long a=2;              long b=3;              long c=0;              for(int i=1;;i++){                  c=a+b;                  a=b;                  b=c;                  if(c>=n)                      break;              }              if(c==n){                  System.out.println("Second win");              }              else                  System.out.println("First win");          }      }  }  

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.