您的位置:首页 > 其它

programming-challenges A multiplication game (110505) 题解

2015-07-23 06:53 399 查看
思路是从结果向开始的情况逆向推算,利用极大值和极小值。代码如下:

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <assert.h>
#include <algorithm>
#include <math.h>
#include <ctime>
#include <functional>
#include <string.h>
#include <stdio.h>
#include <numeric>
#include <float.h>

using namespace std;

int main() {
const string str1 = "Stan wins.";
const string str2 = "Ollie wins.";

long long n = 0;

while (cin >> n) {
int turn = 0;
while (true) {
if (n == 1) {
if (turn % 2 == 1) {
cout << str1 << endl;
}
else {
cout << str2 << endl;
}
break;
}
else {
if (turn % 2 == 0) {
n = ceil((double)n / 9);
}
else {
n = ceil((double)n / 2);
}
turn++;
}
}
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: