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. Windows平台Go调用DLL的坑(居然有这么多没听过的名词)

    最近的项目中,使用了GO来开发一些服务中转程序.业务比较简单,但是有一些业务需要复用原有C++开发的代码.而在WINDOWS,用CGO方式来集成C/C++代码并不是太方便.所以用DLL把C++的代码封 ...

  2. Mybatis 3 返回布尔值,需要注意的地方

    在Mybatis中,有时候需要返回布尔值 ,来确定某个记录行是否存在. 例如: <select id="isExistCode" parameterType="st ...

  3. C++环形矩阵填充实现

    #include<iostream> #include<iomanip> #include<cstdlib> #include<ctime> #incl ...

  4. hdu4521 小明系列的问题——小明序列(LIS变种 (段树+单点更新解决方案))

    链接: huangjing 题目:中文题目 思路: 1:这个题目假设去掉那个距离大于d的条件,那么必定是一个普通的LIS.可是加上那个条件后就变得复杂了.我用的线段树的解法. . .就是採用延迟更新的 ...

  5. Computational Network Toolkit (CNTK) 是微软出品的开源深度学习工具包

    Computational Network Toolkit (CNTK) 是微软出品的开源深度学习工具包 用 CNTK 搞深度学习 (一) 入门 Computational Network Toolk ...

  6. Selenium 2.0 WebDriver 自动化测试 使用教程 实例教程 API快速参考

    Selenium 2.0 WebDriver 自动化测试 使用教程 实例教程 API快速参考 //System.setProperty("webdriver.firefox.bin" ...

  7. uva315(求割点数目)

    传送门:Network 题意:给出一张无向图,求割点的个数. 分析:模板裸题,直接上模板. #include <cstdio> #include <cstring> #incl ...

  8. 实现ListView A~Z快速索引

    ListView A~Z快速索引这种效果在通信录和城市列表中经常看到,方便用户查找,是一种增加用户体验的好方法. 实现步骤: 1.自定义一个名叫SlideBar 的View. 2.在布局文件中加入这个 ...

  9. sdbntrjm57k

    http://www.zhihu.com/collection/24337307 http://www.zhihu.com/collection/24337259 http://www.zhihu.c ...

  10. net 面向接口框架

    Asp.net 面向接口框架之应用程序上下文作用域组件 在团队中推广面向接口开发两年左右,成果总体来说我还是挺满意的,使用面向接口开发的模块使用Unity容器配置的功能非常稳定,便于共享迁移(另一个项 ...