FZU Problem 2102 Solve equation题解
来源:互联网 发布:域名网页制作 编辑:程序博客网 时间:2024/06/05 10:52
Accept: 883 Submit: 2075
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
You are given two positive integers A and B in Base C. For the equation:
We know there always existing many non-negative pairs (k, d) that satisfy the equation above. Now in this problem, we want to maximize k.
For example, A="123" and B="100", C=10. So both A and B are in Base 10. Then we have:
(1) A=0*B+123
(2) A=1*B+23
As we want to maximize k, we finally get one solution: (1, 23)
The range of C is between 2 and 16, and we use 'a', 'b', 'c', 'd', 'e', 'f' to represent 10, 11, 12, 13, 14, 15, respectively.
Input
The first line of the input contains an integer T (T≤10), indicating the number of test cases.
Then T cases, for any case, only 3 positive integers A, B and C (2≤C≤16) in a single line. You can assume that in Base 10, both A and B is less than 2^31.
Output
Sample Input
Sample Output
Source
“高教社杯”第三届福建省大学生程序设计竞赛#include<stdio.h>#include<string.h>#include<algorithm>#include<math.h>using namespace std;int judge(char p[],int x){ int len=strlen(p),ans=0,k,l=1; for(int i=len-1;i>=0;i--) { if(p[i]>='0'&&p[i]<='9') k=p[i]-'0'; else k=p[i]-'a'+10; ans+=l*k; l*=x; } return ans;}int main(){ int t,c; scanf("%d",&t); while(t--) { int ans1,ans2,ans3,ans4; char s1[105],s2[105]; scanf("%s%s%d",s1,s2,&c); ans1=judge(s1,c);//调用函数转换 ans2=judge(s2,c); ans3=ans1/ans2; ans4=ans1%ans2; printf("(%d,%d)\n",ans3,ans4); } return 0;}
- FZU Problem 2102 Solve equation题解
- FZU Problem 2102 Solve equation
- FZU 2102 Solve equation
- FZU 2102 Solve equation
- FZU - 2102 Solve equation
- FZU-2102-Solve equation
- FZU 2102Solve equation
- FZU Problem 2102 Solve equation (数学啊 )
- 【水】FZU 2102 Solve equation
- fzu 2102 Solve equation(水题)
- FZU - 2102 Solve equation(水题)
- FZU 2102 Solve equation (水)
- FZU 2102 Solve equation(规律题)
- F Solve equation(FZU 2102)
- FZU Problem 2102 Solve equation 第三届福建省大学生程序设计竞赛
- FZU 2102 Solve equation (进制转换)
- Solve equation
- Solve equation
- FZU-2111-Min Number
- 技术创业失败的7个教训
- linux --- shell command
- 机器学习面试题---百度2016春招
- LinearLayout 动态添加 TextView 实现标签效果
- FZU Problem 2102 Solve equation题解
- PHP 自动识别当前使用的移动终端
- LIGHT OJ 1259 - Goldbach`s Conjecture(素数筛选)
- ubuntu操作系统安装(二) 十六进制编辑器tweak
- 2016.3.19纪中模拟赛
- 如何将GIT集成到PHPSTORM使用
- 1000 of greedy strategy*
- pause 指令与 rep;nop
- [IOS 开发] 求两点之间的距离