Problem 2102 Solve equation

Accept: 1097    Submit: 2608
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:

A=k*B+d

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

For each test case, output the solution “(k,d)” to the
equation in Base 10.

Sample Input

3
2bc 33f 16
123 100 10
1 1 2

Sample Output

(0,700)
(1,23)
(1,0) 
 
题意:对于形式A=k*B+d,给定A,B两个数,求k,d两个值,且A,B的进制有可能是2~16进制中的其中一种
思路:首先将A,B都换算成10进制,再作除法运算。
AC代码:

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<string>
using namespace std; int base; int translator(string s) {
int sum = ;
for (int i = ; i < s.size();i++) {
if (s[i] >= ''&&s[i] <= '')
sum = sum*base + s[i] - '';
else
sum = sum*base + s[i] - 'a' + ;
}
return sum;
} int main() {
int T;
scanf("%d",&T);
while (T--) {
string s1, s2;
cin >> s1 >> s2;
scanf("%d",&base);
int a = translator(s1);
int b = translator(s2);
int c = a / b;
int mod = a%b;
printf("(%d,%d)\n",c,mod); }
return ;
}

FZOJ 2102 Solve equation的更多相关文章

  1. ACM: FZU 2102 Solve equation - 手速题

     FZU 2102   Solve equation Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  2. FZU 2102 Solve equation(水,进制转化)&& FZU 2111(贪心,交换使数字最小)

    C Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Pra ...

  3. Solve Equation gcd(x,y)=gcd(x+y,lcm(x,y)) gcd(x,y)=1 => gcd(x*y,x+y)=1

    /** 题目:Solve Equation 链接:http://acm.hnust.edu.cn/JudgeOnline/problem.php?id=1643 //最终来源neu oj 2014新生 ...

  4. FZU2102Solve equation

    Problem 2102 Solve equation Accept: 881    Submit: 2065 Time Limit: 1000 mSec    Memory Limit : 3276 ...

  5. 最小二乘法多项式拟合的Java实现

    背景 由项目中需要根据一些已有数据学习出一个y=ax+b的一元二项式,给定了x,y的一些样本数据,通过梯度下降或最小二乘法做多项式拟合得到a.b,解决该问题时,首先想到的是通过spark mllib去 ...

  6. 2017-11-10 Fr Oct 消参

    2017-11-04 Sa $ P(-3, 0) $ 在圆C $ (x-3)^2 + y^2 = 8^2 $ 内,动圆M与圆相切且过P点,求M点轨迹. 设切点 $ A(a, b) $,圆心 \(M(x ...

  7. 机器人关节空间轨迹规划--S型速度规划

    关节空间 VS 操作空间 关节空间与操作空间轨迹规划流程图如下(上标$i$和$f$分别代表起始位置initial和目标位置final): 在关节空间内进行轨迹规划有如下优点: 在线运算量更小,即无需进 ...

  8. 2017-11-04 Sa Oct 消参

    2017-11-04 Sa $ P(-3, 0) $ 在圆C $ (x-3)^2 + y^2 = 8^2 $ 内,动圆M与圆相切且过P点,求M点轨迹. 设切点 $ A(a, b) $,圆心 \(M(x ...

  9. Matlab-5:牛顿迭代法工具箱

    function [f,L]=Newton(f,a) %this is newton teration whic is used for solving implicit One-dimensiona ...

随机推荐

  1. python之golbal/nonlocal

    一.关键字 golbal nonlocal 在局部修改全局的变量为什么会报错 count = 0 def func(): count += 1 func() # UnboundLocalError: ...

  2. $|^|\z|\Z|/a|/l

    #!/usr/bin/perl use strict; use warnings; foreach(<>) { if (/(\w*)/a){print "$1\n";} ...

  3. 记录一次mysql中自定义获取UUID的函数

    循环方式一: DELIMITER :; drop function if exists test.fn_test:; create function test.fn_test() ) begin ) ...

  4. Bootstrap历练实例:标签修饰

    您可以使用修饰的 class label-default.label-primary.label-success.label-info.label-warning.label-danger 来改变标签 ...

  5. Python——流程控制语句

    if语句 条件进行判断,满足,则执行里面 的内容:不满足,则执行if循环下面的语句 基本语法: if 判断条件: 满足后执行语句 1 如果:女人的年龄>30岁,那么:叫阿姨 age_of_gir ...

  6. ios下通过webservice获取数据

    经历了两天的摸索,终于成功获取了数据,因为公司要做一个停车入库的信息查询,所以需要访问webservice的接口,由于没有接触过webservice,所以第一天就是各种搜索资料,类库,各种尝试,甚至是 ...

  7. Linux基础学习-使用vsftpd服务传输文件

    使用vsftpd服务传输文件 1 安装vsftpd [root@qdlinux ~]# yum install vsftpd Loaded plugins: product-id, search-di ...

  8. 【linux】【CPU】【x86】平台说明

    节选自 <鸟哥的linux私房菜> http://cn.linux.vbird.org/linux_basic/0520rpm_and_srpm_1.php 操作硬件平台:这是个很好玩的地 ...

  9. Python基础-函数参数

    Python基础-函数参数 写在前面 如非特别说明,下文均基于Python3 摘要 本文详细介绍了函数的各种形参类型,包括位置参数,默认参数值,关键字参数,任意参数列表,强制关键字参数:也介绍了调用函 ...

  10. Django之cookie、session

    会话跟踪技术 可以把会话理解为客户端与服务器之间的一次会晤,在一次会晤中可能会包含多次请求和响应. 一次会话过程中,我们应该注意的是什么呢? 那就是,一些操作要保证用户操作的是用户自己个人的数据.举个 ...