中级农民
- 积分
- 133
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2011-3-5
- 最后登录
- 1970-1-1
|
#include <iostream>
#include <stack>
#include <assert.h>
using namespace std;
int multiply(int n, int m)
{
int r = 0;
for (int i = 0; i < m; ++i)
r += n;
return r;
}
int divide(int n, int m)
{
assert(m);
stack<int> s;
s.push(1);
while(multiply(s.top() + s.top(), m) < n)
s.push(s.top() + s.top());
int b = s.top();
s.pop();
while(true)
{
if(multiply (b+s.top(), m) < n)
b += s.top();
else if (multiply (b + s.top(), m) == n)
return b + s.top();
assert(s.size());
s.pop();
}
} |
|