Codeforces 102202D-A Plus Equals B【思维】 难度:**
题意:
A + B is a problem used to test one’s basic knowledge for competitive programming. Here is yet another boring variation of it.
You have two integers, A and B. You want to make them equal. To do so, you can perform several steps, where each step is one of the following:
A+=A
A+=B
B+=A
B+=B
Unfortunately, A + B is a hard problem for us, so you are allowed to make at most 5000 steps.
Input
Two integers A, B are given. (1 ≤ A, B ≤ 1018).
Output
In the first line, print a single integer n (0 ≤ n ≤ 5000) denoting the number of steps.
In next n lines, print one of the following strings to denote your desired operation: “A+=A”, “A+=B”, “B+=A”, or “B+=B”.
Any sequence of steps that yields the desired result will be judged correct.
Example
inputCopy
2 3
outputCopy
4
B+=B
B+=A
A+=A
A+=A
题解:
虽然这题的数字是在向上叠加的,但我们不能真的去向上叠加,一是因为向上坑太大,没办法处理两个数的关系,二是对于大数会爆long long。观察后可以发现A+=A的本质是B-=B,B+=B的本质是A-=A,这样处理可以保持两个数时刻处于纠缠的状态。因此我们只需遇到偶数就除以二并时刻进行辗转相减即可。
代码:
#include<stdio.h>
int main()
{long long a,b,c,d;int times=0;scanf("%lld%lld",&a,&b);c=a;d=b;while(a!=b){while(a%2==0){times++;a/=2;}while(b%2==0){times++;b/=2;}if(a==b)break;if(a<b)b+=a;else a+=b;times++;}printf("%d\n",times);a=c;b=d;while(a!=b){while(a%2==0){printf("B+=B\n");a/=2;}while(b%2==0){printf("A+=A\n");b/=2;}if(a==b)break;if(a<b){b+=a;printf("B+=A\n");}else{a+=b;printf("A+=B\n");}}
}
Codeforces 102202D-A Plus Equals B【思维】 难度:**相关推荐
- Codeforces Round #459 (Div. 2) C 思维,贪心 D 记忆化dp
Codeforces Round #459 (Div. 2) C. The Monster 题意:定义正确的括号串,是能够全部匹配的左右括号串. 给出一个字符串,有 (.). ? 三种字符, ? 可以 ...
- codeforces 148 C. Terse princess(思维,构造)
C. Terse princess(思维,构造) 题目链接:codeforces 148C 题意: 有个公主找王子,如果这个人比之前所有王子的财富都高,公主就会Oh, ...
- CodeForces - 1498D Bananas in a Microwave(思维+dp)
题目链接:点击查看 题目大意:给出 nnn 次操作,初始时有一个 k=0k=0k=0,每次操作抽象为三个数 txyt\ x\ yt x y,其中 xxx 可能为小数,可以选择一个 num∈[0,y]n ...
- CodeForces - 813E Army Creation(主席树+思维)
题目链接:点击查看 题目大意:给出一个长度为 nnn 的数列和一个整数 kkk,现在有 qqq 次询问,每次询问给出一个区间 [l,r][l,r][l,r],设 cnticnt_icnti 为数字 ...
- CodeForces - 1030C Vasya and Golden Ticket(思维)
题目链接:点击查看 题目大意:给定长度为n的字符串,字符串全部由0~9的数字组成,要求将字符串划分为连续的子字符串,要求每个子字符串的和都要相等,问给定字符串能否成功划分 题目分析:简单思维,因为划分 ...
- B - Average Numbers CodeForces - 134A(水题,思维)
You are given a sequence of positive integers a1, a2, -, an. Find all such indices i, that the i-th ...
- CodeForces - 1245A Good ol' Numbers Coloring (思维)
Codeforces Round #597 (Div. 2 Consider the set of all nonnegative integers: 0,1,2,-. Given two integ ...
- 【CodeForces - 988C 】Equal Sums (思维,STLmap,STLset,tricks)
题干: You are given kk sequences of integers. The length of the ii-th sequence equals to nini. You hav ...
- 【CodeForces - 298C】Parity Game (思维,有坑)
题干: You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar be ...
- 【CodeForces - 255B】Code Parsing(思维,字符串)
题干: Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vi ...
最新文章
- [导入][翻译]匈牙利命名法的缺点
- MspEmu W.I.P.
- Standard Template Library标准模板库专项复习总结(一)
- Boost:boost::callable_traits::function_type_t的测试程序
- Android开发5——文件读写
- Golang 推荐的命名规范
- 【求助】小系统组成大系统所遇到的问题
- dp笔记:关于DP算法和滚动数组优化的思考
- 介绍最全的LVS负载均衡技术
- 使用Discuz!自带参数防御CC攻击以及原理,修改Discuz X 开启防CC攻击后,不影响搜索引擎收录的方法...
- 电信设置的nat 虚拟服务器192.168.1.3 是什么,VMware WorkStation的三种网络连接方式详解...
- IT招聘负责人:成功简历六大要素
- H5的video用法
- 在VS中一个项目下两个以上源文件怎么通过编译
- 2019个税计算公式(附最新个税计算器)
- LEADTOOLS V20,史无前例荣耀归来!!!
- 渗透测试(面试)如何获取一个网站的真实ip
- 春节购机如何选?老司机会告诉你买华为Mate 20 Pro
- CTF网络安全大赛介绍
- 具统计全国淘宝村增至211个 直接就业超过28万人
热门文章
- Deep Learning with Python 读书笔记6.26 I 什么是深度学习
- Win10自带输入法突然变繁体如何改回简体?
- 最大打开文件数(文件句柄数)
- 提高组模拟试题七第二试 佐佐小次郎
- 图像分割——线检测——拉普拉斯标定(Matlab)
- 不是计算机硬件有哪些,电脑基本硬件有哪些(除了可以看到的还有哪些)
- 纯前端实现 传统验证码功能
- 【算法思考】Pytorch Align Corners 用法总结
- 学习 TransFuse: Fusing Transformers and CNNs for Medical Image Segmentation 医学分割
- 张勇:2019年,阿里巴巴要找这样的人