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
  1. 11 5 9
  1. 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 符号问题。由于这里仅仅求差异就能够了。所以返回绝对值就够了。
这样做本题还是有一定难度。 并且能够锻炼到一些高级点的知识的运用。挺好。


  1. #include <string>
  2. #include <vector>
  3. #include <map>
  4. #include <algorithm>
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. namespace
  9. {
  10.  
  11. bool sLarger(const string s, const string t)
  12. {
  13. if (s.size() < t.size()) return false;
  14. else if (s.size() > t.size()) return true;
  15. return s > t;
  16. }
  17.  
  18. string operator-(string s, string t)
  19. {
  20. if (s == t) return "0";
  21. string x;
  22. //bool sign = true;不用sign,求其绝对值就可以
  23. if (sLarger(t, s))
  24. {
  25. s.swap(t);
  26. }
  27.  
  28. bool carry = 0;
  29. for (int i = s.size()-1, j = t.size()-1; i>=0 || j>=0 ; i--, j--)
  30. {
  31. int a = i>=0? s[i] - '0' : 0;
  32. int b = j>=0?
  33.  
  34. t[j] - '0' : 0;
  35. int sub = a - b - carry;
  36. carry = 0;
  37. if (sub < 0)
  38. {
  39. sub += 10;
  40. carry = 1;
  41. }
  42. x.push_back(sub+'0');
  43. }
  44. while (x.size() && '0' == x.back()) x.pop_back();
  45. reverse(x.begin(), x.end());
  46. return x;
  47. }
  48.  
  49. }//empty namespace end
  50.  
  51. void Anindilyakwa1777()
  52. {
  53. vector<string> piles(3);
  54. cin>>piles[0]>>piles[1]>>piles[2];
  55. sort(piles.begin(), piles.end(), sLarger);
  56.  
  57. int c = 0;
  58. while (true)
  59. {
  60. c++;
  61. string minSub = piles[1]-piles[0];
  62. for (int i = 2; i < (int)piles.size(); i++)
  63. {
  64. string sub = piles[i]-piles[i-1];
  65. if (sLarger(minSub, sub)) minSub = sub;
  66. }
  67. if ("0" == minSub) break;
  68. piles.push_back(minSub);
  69. sort(piles.begin(), piles.end(), sLarger);
  70. }
  71. cout<<c;
  72. }


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. Mybatis在oracle、mysql、db2、sql server的like模糊查询

    <!-- oracle --> <select id="searchUserBySearchName" parameterType="java.lang ...

  2. [C++]指针浅析

    Date: 2014-1-4 summary: 指针的简单理解,概念性的东西会比较多(100个人有100种理解,此处只代表我个人看法) Contents: 1.什么是指针 c++ primer plu ...

  3. Android资源文件及文件夹介绍

    在Android项目文件夹里面,主要的资源文件是放在res文件夹里面的 1:assets文件夹是存放不进行编译加工的原生文件,即该文件夹里面的文件不会像xml,java文件被预编译,可以存放一些图片, ...

  4. 常见问题(FAQ) | VPNCUP

    常见问题(FAQ) | VPNCUP 常见问题(FAQ) 关于FAQ 新手开始 登录验证问题 为什么刚注册后,登录VPN服务器提示错误? 免费注册的用户有哪些限制? 为什么连接免费VPN后20分钟自动 ...

  5. [置顶] 如何在Python IDLE中调试Python代码?

    好久没有用Python了,居然忘记了怎么在Python IDLE中调试Python代码.百度了一下,然后还是写下来吧,以免以后又忘记了. 1. Set break point in the sourc ...

  6. Oracle GoldenGate for Oracle 11g to PostgreSQL 9.2.4 Configuration

    Installing and setting up Oracle GoldenGate connecting to an Oracle database Also please make sure t ...

  7. Object.Instantiate 实例

    static function Instantiate (original : Object, position : Vector3, rotation : Quaternion) : Object ...

  8. poj 1991 Turning in Homework dp

    这个可以证明必须从两边的任务开始交起,因为中间交的任务可以后面经过的时候再交,所以就变成了一个n*n的dp. #include <iostream> #include <cstdio ...

  9. weblogic环境,应用上传图片报Could not initialize class sun.awt.X11.XToolkit

    问题描写叙述 遇到的问题是在weblogic环境,应用在上传图片的时候报Could not initialize class sun.awt.X11.XToolkit 错误. 详细错误例如以下 17: ...

  10. Andorid Clip 实现自定义的进度条效果实例

    Android该系统提供了一个水平进度条为我们展现了运行使用进展情况,水平进度条显示用于运行进度Clip Drawable技术 下面我们通过一个具体的例子来说明Clip Drawable使用. 还有我 ...