The language of Australian aborigines anindilyakwa has no numerals. No anindilyakwa can say: “I've hooked eight fishes”. Instead, he says: “I've hooked as many fishes as many stones are in this pile”.
Professor Brian Butterworth found a meadow with three piles of stones. He decided to determine whether aborigines can count. Professor asked one of the aborigines to point at two piles with the minimal
difference of numbers of stones in them and tell what this difference is. The aborigine pointed correctly! He was unable to express the difference with words, so he went to a shore and returned with a pile of the corresponding number of stones.
Professor decided to continue his experiments with other aborigines, until one of them points at two piles with equal number of stones. All piles that aborigines bring from the shore are left at the
meadow. So, the second aborigine will have to deal with one more pile, the one brought by the first aborigine.

Input

The only input line contains space-separated pairwise distinct integers x1, x2 and x3(1
≤ x1, x2, x3 ≤
1018), which are the numbers of stones in piles that were lying on the meadow at the moment professor Butterworth asked the first aborigine.

Output

Output the number of aborigines that will have to answer a stupid question by professor.

Sample

input output
11 5 9
3

Hint

The first aborigine will point at piles of 11 and 9 stones and will bring a pile of two stones. The second aborigine will point at the same piles and will bring another pile of two stones. The third
aborigine will point at two piles of two stones, and the experiments will be over.

本题能够使用长整形来记录数据的。由于最长只是10^8。可是假设把这题当做是无穷大数来做的话。难度指数就直线上升了。

这里给出使用string来做无穷大减法的解法。
要处理的问题:
1 string大小比較问题,不能使用原始的<号
2 怎样进位的问题
3 符号问题。由于这里仅仅求差异就能够了。所以返回绝对值就够了。
这样做本题还是有一定难度。 并且能够锻炼到一些高级点的知识的运用。挺好。


#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
using namespace std; namespace
{ bool sLarger(const string s, const string t)
{
if (s.size() < t.size()) return false;
else if (s.size() > t.size()) return true;
return s > t;
} string operator-(string s, string t)
{
if (s == t) return "0";
string x;
//bool sign = true;不用sign,求其绝对值就可以
if (sLarger(t, s))
{
s.swap(t);
} bool carry = 0;
for (int i = s.size()-1, j = t.size()-1; i>=0 || j>=0 ; i--, j--)
{
int a = i>=0? s[i] - '0' : 0;
int b = j>=0? t[j] - '0' : 0;
int sub = a - b - carry;
carry = 0;
if (sub < 0)
{
sub += 10;
carry = 1;
}
x.push_back(sub+'0');
}
while (x.size() && '0' == x.back()) x.pop_back();
reverse(x.begin(), x.end());
return x;
} }//empty namespace end void Anindilyakwa1777()
{
vector<string> piles(3);
cin>>piles[0]>>piles[1]>>piles[2];
sort(piles.begin(), piles.end(), sLarger); int c = 0;
while (true)
{
c++;
string minSub = piles[1]-piles[0];
for (int i = 2; i < (int)piles.size(); i++)
{
string sub = piles[i]-piles[i-1];
if (sLarger(minSub, sub)) minSub = sub;
}
if ("0" == minSub) break;
piles.push_back(minSub);
sort(piles.begin(), piles.end(), sLarger);
}
cout<<c;
}


Timus 1777. Anindilyakwa 奇怪的问题计数的更多相关文章

  1. CF1083B The Fair Nut and String

    题意 给出两个长度为n的01字符串S和T. 选出k个字典序在S和T之间的长度为n的01字符串,使得尽可能多的字符串满足其是所选字符串中至少一个串的前缀. 这是一道思路比较奇怪的类似计数dp的题. 首先 ...

  2. URAL 1777 D - Anindilyakwa 暴力

    D - AnindilyakwaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/v ...

  3. 【vijos】1789 String(组合计数+奇怪的题)

    https://vijos.org/p/1789 我yy了一下发现我的方法没错啊,为嘛才80分..(后来看了题解,噗,还要判断k>n和k=1的情况QAQ 当k=1的时候,答案显然是m^n 当k& ...

  4. BZOJ 1211: [HNOI2004]树的计数( 组合数学 )

    知道prufer序列就能写...就是求个可重集的排列...先判掉奇怪的情况, 然后答案是(N-2)!/π(d[i]-1)! -------------------------------------- ...

  5. 康复计划#5 Matrix-Tree定理(生成树计数)的另类证明和简单拓展

    本篇口胡写给我自己这样的什么都乱证一通的口胡选手 以及那些刚学Matrix-Tree,大致理解了常见的证明但还想看看有什么简单拓展的人- 大概讲一下我自己对Matrix-Tree定理的一些理解.常见版 ...

  6. C#版 - PAT乙级(Basic Level)真题 之 1024.科学计数法转化为普通数字 - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. PAT Bas ...

  7. 『Python』为什么调用函数会令引用计数+2

    一.问题描述 Python中的垃圾回收是以引用计数为主,分代收集为辅,引用计数的缺陷是循环引用的问题.在Python中,如果一个对象的引用数为0,Python虚拟机就会回收这个对象的内存. sys.g ...

  8. bzoj 3195 [Jxoi2012]奇怪的道路

    3195: [Jxoi2012]奇怪的道路 Description 小宇从历史书上了解到一个古老的文明.这个文明在各个方面高度发达,交通方面也不例外.考古学家已经知道,这个文明在全盛时期有n座城市,编 ...

  9. 奇怪的分式|2014年蓝桥杯B组题解析第六题-fishers

    奇怪的分式 上小学的时候,小明经常自己发明新算法.一次,老师出的题目是: 1/4 乘以 8/5 小明居然把分子拼接在一起,分母拼接在一起,答案是:18/45 (参见图1.png) 老师刚想批评他,转念 ...

随机推荐

  1. linux 下opensplice的简易安装

    http://www.prismtech.com/opensplice/opensplice-dds-community/software-downloads 下载对应我选择的是: OpenSplic ...

  2. 关于ubuntu下qt编译显示Cannot connect creator comm socket /tmp/qt_temp.xxx/stub-socket的解决的方法

    今天在ubuntu下安装了qtcreator,准备測试一下能否用.果然一測试就出问题了,简单编写后F5编译在gnome-terminal中出现 Cannot connect creator comm ...

  3. ACM-最小生成树之畅通project——hdu1863

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

  4. A Game of Thrones(19) - Jon

    The courtyard rang to the song of swords. Under black wool, boiled leather, and mail, sweat trickled ...

  5. RFC2889转发性能測试用例设计和自己主动化脚本实现

    一.203_TC_FrameRate-1.tcl set chassisAddr 10.132.238.190 set islot 1 set portList {9 10} ;#端口的排列顺序是po ...

  6. jQuery 顶部导航尾随滚动,固定浮动在顶部

    jQuery 顶部导航尾随滚动.固定浮动在顶部 演示 XML/HTML Code <section> <article class="left"> < ...

  7. Android actionbar 搜索框

    就是实如今顶部这种搜索框. 一.这个搜索框是actionbar上的menu上的一个item.叫SearchView.我们能够先在menu选项里定义好: bmap_menu.xml: <?xml ...

  8. jQuery 自学笔记—5 遍历

    什么是遍历? jQuery 遍历,意为“移动”,用于根据其相对于其他元素的关系来“查找”(或选取)HTML 元素.以某项选择开始,并沿着这个选择移动,直到抵达您期望的元素为止. 下图展示了一个家族树. ...

  9. 【从翻译mos文章】SGA_TARGET与SHMMAX关系

    SGA_TARGET与SHMMAX关系 参考原始: Relationship Between SGA_TARGET and SHMMAX (文件 ID 1527109.1) 申请: Oracle Da ...

  10. WPF案例 (四) 模拟Windows7桌面任务栏

    原文:WPF案例 (四) 模拟Windows7桌面任务栏 这个程序模彷了Windows7的桌面任务栏,当在桌面上双击某个快捷方式时,将打开一个新的子界面,并且在任务栏里创建一个链接到此界面的任务栏图标 ...