UVa 550 Multiplying by Rotation
来源:互联网 发布:淘宝男迷彩加绒衫 编辑:程序博客网 时间:2024/04/28 02:25
【解题思路】
参考了一下别人的思路,发现这个题目有点绕,要求输出满足条件的最小位数,现就输入样例进行分析。
输入样例1
10 7 4
表明输入的数字末位为7,乘数为4,进制为十进制。将7乘上4,得28,开始执行如下循环:
(1)得到的数字是否为7?若是,结束循环,统计完整的循环次数。否则,转步骤(2)。
(2)将该乘数除以进制10,求得商d;将原乘数再对进制10求模,求得余数r。转步骤(3)。
(3)将余数r作为新的被乘位,乘上4,加上之前的进位d。转步骤(1)。
即 7*4=28
28 != 7 28/10=2 28%10=88*4+2=34
34 != 7 34/10=3 34%10=44*4+3=19
19 != 7 19/10=1 19%10=99*4+1=37
37 != 7 37/10=3 37%10=77*4+3=31
31 != 7 31/10=3 31%10=11*4+3=7
7 == 7结束
经过循环后,被乘数相当于增长了5位,共6位。
输入样例2
9 7 4
表明输入的数字末位为7,乘数为4,进制为九进制。将7乘上4,得28,循环中的进制为九进制,仿照如上循环即可。
即 7*4=28
28 != 7 28/9=3 28%9=1 1*4+3=7
7 == 7结束
经过循环后,被乘数相当于增长了1位,共2位。
步骤(3)就相当于把结果看做对应的进制,取其低位作为被乘数的高位,这样就模拟了循环右移一位的过程。
【代码】
#include<stdio.h>#include<string.h>int main() {int base, digit, mult;int ans, temp;int d, r;while (~scanf("%d %d %d", &base, &digit, &mult)) {ans = 1; //统计位数temp = digit*mult;while (temp != digit) {ans ++;d = temp/base;r = temp%base;temp = r*mult+d;}printf("%d\n", ans);}return 0;}
0 0
- uva 550 - Multiplying by Rotation
- Uva 550 - Multiplying by Rotation
- uva 550 - Multiplying by Rotation
- UVa 550 Multiplying by Rotation
- UVa 550 - Multiplying by Rotation
- UVA 550 - Multiplying by Rotation
- UVa 550 - Multiplying by Rotation
- UVa 550: Multiplying by Rotation
- UVA 550 - Multiplying by Rotation
- Uva 550 - Multiplying by Rotation
- uva 550 - Multiplying by Rotation
- uva 550 Multiplying by Rotation
- uva 550 - Multiplying by Rotation
- UVa 550 - Multiplying by Rotation
- UVa 550 - Multiplying by Rotation
- Uva 550 Multiplying by Rotation
- UVA - 550 Multiplying by Rotation
- UVa 550 Multiplying by Rotation
- 迷茫了好一阵决定做WEB前端
- poj 1151 Atlantis 二分查找+离散化
- POJ-3026 Borg Maze(最小生成树)
- HDU1531 King 【差分约束系统】
- 查询 oracle sid 实例名
- UVa 550 Multiplying by Rotation
- llvm 初探
- ASPNETCOMPILER : error ASPRUNTIME: 未将对象引用设置到对象的实例
- 自动化测试里的数据驱动和关键字驱动思路的理解
- android:inputType参数类型说明
- linux文件操作相关函数
- c项目中指定头文件目录
- 开发中遇到的异常
- hdu 3257 Hello World!(位运算 & 模拟)