版本1和6间的区别 (跳过第5版)
于2006-03-11 16:01:21修订的的版本1
大小: 936
编辑: czk
备注:
于2008-02-23 15:34:59修订的的版本6
大小: 1518
编辑: localhost
备注: converted to 1.6 markup
删除的内容标记成这样。 加入的内容标记成这样。
行号 1: 行号 1:
## page was renamed from 程序设计练习10——zju2290——Game
行号 2: 行号 3:

http://acm.zju.edu.cn/show_problem.php?pid=2290
行号 6: 行号 10:
Two players(A and B) take turns to take stones form a heap of N stones. Two players( A and B ) take turns to take stones form a heap of N stones.
行号 28: 行号 32:
http://acm.zju.edu.cn/show_problem.php?pid=2290
行号 30: 行号 34:

{{{#!cplusplus
/*Written by czk*/
#include<iostream>
#include<vector>
using namespace std;

int g(int n) {
 int i = n;
 while(1){
  int j1 = 1, j2 = 2;
  while(j2<i) {
   j2 = j1 + j2;
   j1 = j2 - j1;
  }
  if(j2==i || i ==1 )
   return i==n? 0 : i;
  else
   i-=j1;
 }
}
int main()
{
 int i;
 while(cin>>i) {
 //for(i = 2; i< 1000; i++){
 // cout << i<<'\t';
  int win = g(i);
  if(win)
   cout << win << endl;
  else
   cout << "lose" << endl;
 }
 return 0;
}
}}}

Game

http://acm.zju.edu.cn/show_problem.php?pid=2290

Time limit: 1 Seconds

Memory limit: 32768K

Two players( A and B ) take turns to take stones form a heap of N stones.

There are some rules:

  1. A always takes first. He can take arbitrary number of stones but not all of them.
  2. The number of the one who will take should less than or equal the twice of the other one taken last time. But must more than one or one.
  3. The one who take take the last one stone is the winner.
  4. The two players are clever enough, they can make the best choice.

1. Input

Every test case has only one line with one integer N(2 <= N <= 100000000), the numbers of the stones.

2. Output

If A will lose output "lose"

If A can win,output the numbers A should take at the first time. If there are more ways to make A win, output the smallest one.

3. Sample Input

zju2290 (2008-02-23 15:34:59由localhost编辑)

ch3n2k.com | Copyright (c) 2004-2020 czk.