Timus 1777. Anindilyakwa 奇怪的问题计数
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.
meadow. So, the second aborigine will have to deal with one more pile, the one brought by the first aborigine.
Input
≤ 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
Sample
| input | output |
|---|---|
11 5 9 |
3 |
Hint
aborigine will point at two piles of two stones, and the experiments will be over.
#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 奇怪的问题计数的更多相关文章
- CF1083B The Fair Nut and String
题意 给出两个长度为n的01字符串S和T. 选出k个字典序在S和T之间的长度为n的01字符串,使得尽可能多的字符串满足其是所选字符串中至少一个串的前缀. 这是一道思路比较奇怪的类似计数dp的题. 首先 ...
- URAL 1777 D - Anindilyakwa 暴力
D - AnindilyakwaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/v ...
- 【vijos】1789 String(组合计数+奇怪的题)
https://vijos.org/p/1789 我yy了一下发现我的方法没错啊,为嘛才80分..(后来看了题解,噗,还要判断k>n和k=1的情况QAQ 当k=1的时候,答案显然是m^n 当k& ...
- BZOJ 1211: [HNOI2004]树的计数( 组合数学 )
知道prufer序列就能写...就是求个可重集的排列...先判掉奇怪的情况, 然后答案是(N-2)!/π(d[i]-1)! -------------------------------------- ...
- 康复计划#5 Matrix-Tree定理(生成树计数)的另类证明和简单拓展
本篇口胡写给我自己这样的什么都乱证一通的口胡选手 以及那些刚学Matrix-Tree,大致理解了常见的证明但还想看看有什么简单拓展的人- 大概讲一下我自己对Matrix-Tree定理的一些理解.常见版 ...
- C#版 - PAT乙级(Basic Level)真题 之 1024.科学计数法转化为普通数字 - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. PAT Bas ...
- 『Python』为什么调用函数会令引用计数+2
一.问题描述 Python中的垃圾回收是以引用计数为主,分代收集为辅,引用计数的缺陷是循环引用的问题.在Python中,如果一个对象的引用数为0,Python虚拟机就会回收这个对象的内存. sys.g ...
- bzoj 3195 [Jxoi2012]奇怪的道路
3195: [Jxoi2012]奇怪的道路 Description 小宇从历史书上了解到一个古老的文明.这个文明在各个方面高度发达,交通方面也不例外.考古学家已经知道,这个文明在全盛时期有n座城市,编 ...
- 奇怪的分式|2014年蓝桥杯B组题解析第六题-fishers
奇怪的分式 上小学的时候,小明经常自己发明新算法.一次,老师出的题目是: 1/4 乘以 8/5 小明居然把分子拼接在一起,分母拼接在一起,答案是:18/45 (参见图1.png) 老师刚想批评他,转念 ...
随机推荐
- CDOJ 1221 Ancient Go
题目链接:http://acm.uestc.edu.cn/#/problem/show/1221 题目分类:dfs 代码: #include<bits/stdc++.h> using na ...
- 用Python对体积较大的CSV文件进行比较的经验
用Python对体积较大的CSV文件进行比较的经验 » 进化的测试 | 进化的测试 用Python对体积较大的CSV文件进行比较的经验 python Add comments 八 032010 ...
- Linux温馨提示1--安装U板块和Windwos划分
一.安装U盘 现在我用Ubuntu12.04在插入U光盘将被直接安装到/media/下, 10:33linc@Linc-Ubuntu:linc$ df -h Filesystem Size Used ...
- Android开发之模板模式初探
模板模式我认为在Android的开发中是最长用到的,基本是随处可见的,认识该模式,有助于我们对Android的源代码及框架有一个更深层次的认识.那什么是模板模式呢,模板模式就是定义一个基本框架,将当中 ...
- poj3694(tarjan缩点+lca)
传送门:Network 题意:给你一个连通图,然后再给你n个询问,每个询问给一个点u,v表示加上u,v之后又多少个桥. 分析:方法(1219ms):用并查集缩点,把不是桥的点缩成一个点,然后全图都是桥 ...
- hdu1709(母函数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1709 题意: 给你一个n,表示n个物品,下面有n个数,表示n个物品的重量,然后进行称量,每个物品只有一 ...
- 在Sublime Text3中运行PHP代码
一.前言 最近由于工作需要要与第三方系统对接,另外由于文档中关于其中几个接口就只有很简单的描述,弄了半天都没有弄成功.跟第三方负责的人沟通后还是没有找到具体问题出在哪里,另外因为他们没有开发人员懂.n ...
- Windows 10Bash命令
Windows 10预览版14316开启Bash命令支持 00x0 前言 4月7日凌晨,微软推送了最新的Windows 10一周年更新预览版14316,其中重要的是原生支持Linux Bash命令行支 ...
- The Django template language 阅读批注
The Django template language About this document This document explains the language syntax of the D ...
- (转)Python获取当时时间
我有的时候写程序要用到当前时间,我就想用python去取当前的时间,虽然不是很难,但是老是忘记,用一次丢一次, 为了能够更好的记住,我今天特意写下python 当前时间这篇文章,如果你觉的对你有用的话 ...