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; }
相关文章推荐
- Git 使用中的问题
- Scala中隐式转换内幕操作规则揭秘
- 多线程(线程的概述,创建线程,控制线程,线程同步,线程池)
- 如何打印运行时加载类的包名(物理包名,不是路径)
- 优步司机如何联系客服?uber客服渠道,Uber优步司机客服渠道
- LeetCode Happy Number
- LeetCode Happy Number
- spring官网下载jar包
- UberX及以上级别车奖励政策(优步北京第四组)
- UberX及以上级别车奖励政策(优步北京第二、三组)
- UberX及以上级别车奖励政策(优步北京第一组)
- RedHat5.8更改yum源
- leetcode 240: Search a 2D Matrix II
- 读书笔记 day1:The design of approximation algorithms
- #leetcode#Search a 2D Matrix II
- 34款Firefox渗透测试插件
- Leetcode NO.155 Min Stack
- HP笔记本 开机显示Boot device not found
- C++ 学习之 批量数据的储存
- LeetCode Isomorphic Strings