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. 解读express框架

    #解读Express 框架 1. package.json文件:express工程的配置文件 2. 为什么可以执行npm start?相当于执行 node ./bin/www "script ...

  2. 2d游戏中的射线与矩形检测碰撞

    cc.exports.LineCollideRect(startLine,endLine,rect)--向量与矩形检测碰撞 --获取矩形的四个顶点位置 local p = {cc.p(rect.x,r ...

  3. cocos2dx 3.x lua 网络加载并且保存资源(unix、linux)

    #ifndef __DazzleParkour__TextLoader__ #define __DazzleParkour__TextLoader__ #include <stdio.h> ...

  4. verilog 1995 VS 2001 part1模块声明的扩展

    1.模块声明的扩展 (1)端口声明(input/output/inout)同数据类型声明(reg /wire)放在同一语句中. (2)ANSI C风格的端口声明可以用于module/task/func ...

  5. php 关于金额的几种计算方式

    php 关于金额的几种计算方式 平常开始开发过程中,多多少少都会遇到点关于金额的计算,比如设置返利.提现手续费.折扣啊等等诸如此类的比例,然后再计算出之后的实际的费用. 下面,以折扣为例,来实现这类计 ...

  6. Juicer 轻量级javascript模板引擎

    juicer是一个javascript轻量级模板引擎. 使用方法 编译模板并根据数据立即渲染出结果 1 juicer(tpl, data); 仅编译模板暂不渲染,返回一个可重用的编译后的函数 1 va ...

  7. 《linux设备驱动开发详解》笔记——7并发控制

    linux中并发无处不在,底层驱动需要考虑. 7.1 并发与竞争 7.1.1 概念 并发:Concurrency,多个执行单元同时.并行执行 竞争:Race Condistions,并发的执行单元对共 ...

  8. numpy 三个点的使用[...]

    numpy [...]语法简单使用 Python numpy中切片功能与列表切片类似,但功能更加强大 本文主讲numpy中[...]的简单使用,后续工作继续补充. import numpy >& ...

  9. matplotlib学习记录 六

    # 绘制多数据条形图 # 假设你知道了列表a中电影分别在2017-09-14(b_14),2017-09-15(b_15), # 2017-09-16(b_16)三天的票房,为了展示列表中电影本身的票 ...

  10. PAT Basic 1078

    1078 字符串压缩与解压 文本压缩有很多种方法,这里我们只考虑最简单的一种:把由相同字符组成的一个连续的片段用这个字符和片段中含有这个字符的个数来表示.例如 ccccc 就用 5c 来表示.如果字符 ...