A Multiplication Game

这道题目用的是博奕算法。

// A Multiplication Game.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> using namespace std; bool Multiplication(long n){ if(n>1&&n<=9)return true; else if(n>9&&n<=18)return false; if(n%9==0)n=n/9; else n=n/9+1; if(n%2==0)n=n/2; else n=n/2+1; return Multiplication(n); } int _tmain(int argc, _TCHAR* argv[]) { long n=0; while(cin>>n){ if(Multiplication(n)==true)cout<<"Stan wins"<<"/n"; else cout<<"Ollie wins"<<"/n"; } return 0; }  

你可能感兴趣的:(算法)