F Solve equation(FZU 2102)
来源:互联网 发布:excel剪切板数据 编辑:程序博客网 时间:2024/06/05 11:30
F Solve equation
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.
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.
32bc 33f 16123 100 101 1 2
(0,700)(1,23)(1,0)
题意分析:
第一行输入一个整数T,接下来有T组数据
每行输入三个数a,b,c;
其中c代表a,b的进制,例如c=3,那a和b就是三进制数。
我们要先把a,b化为10进制数。
然后输出(k,d)中k为a/b,d为a%b。
代码如下:
#include<stdio.h>#include<algorithm>#include<string.h>using namespace std;int main(){ int t; scanf("%d",&t); while(t--) { char a[105],b[105]; int n; int x=0,y=0,c=0,d=0; scanf("%s%s%d",&a,&b,&n); int len1=strlen(a); int len2=strlen(b); int k=1,l=1; for(int i=len1-1; i>=0; i--) //求a的十进制数 { if(a[i]>='a') a[i]=a[i]-'a'+10; else a[i]=a[i]-'0'; x+=a[i]*k; k*=n; } for(int i=len2-1; i>=0; i--) //求b的十进制数 { if(b[i]>='a') b[i]=b[i]-'a'+10; else b[i]=b[i]-'0'; y+=b[i]*l; l*=n; } c=x/y; d=x%y; printf("(%d,%d)\n",c,d); } return 0;}
- F Solve equation(FZU 2102)
- FZU 2102 Solve equation
- FZU 2102 Solve equation
- FZU - 2102 Solve equation
- FZU-2102-Solve equation
- FZU 2102Solve equation
- fzu 2102 Solve equation(水题)
- FZU - 2102 Solve equation(水题)
- FZU 2102 Solve equation (水)
- FZU 2102 Solve equation(规律题)
- FZU Problem 2102 Solve equation
- 【水】FZU 2102 Solve equation
- FZU Problem 2102 Solve equation (数学啊 )
- FZU 2102 Solve equation (进制转换)
- FZU Problem 2102 Solve equation题解
- FZU Problem 2102 Solve equation 第三届福建省大学生程序设计竞赛
- Solve equation
- Solve equation
- 蓝桥杯训练:基础训练——时间转化
- nyoj307 宝物(最短路+贪心)
- java:二维数组替换
- 64. Minimum Path Sum
- 蓝桥杯训练:基础训练——
- F Solve equation(FZU 2102)
- 转载:零基础写Java知乎爬虫之先拿百度首页练练手
- linux下的DNS服务
- HDU 2222-Keywords Search
- 20
- 深入浅出:Linux设备驱动之字符设备驱动
- Tarjan’s off-line lowest common ancestors algorithm
- vb.net 教程 8-2 简单的SQL语言1
- Alice做算术 I