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. DROP OPERATOR - 删除一个操作符

    SYNOPSIS DROP OPERATOR name ( lefttype | NONE , righttype | NONE ) [ CASCADE | RESTRICT ] DESCRIPTIO ...

  2. PAT (Basic Level) Practise (中文)- 1010. 一元多项式求导 (25)

    http://www.patest.cn/contests/pat-b-practise/1010 设计函数求一元多项式的导数.(注:xn(n为整数)的一阶导数为n*xn-1.) 输入格式:以指数递降 ...

  3. MySql下最好用的数据库管理工具是哪个

    MySql下最好用的数据库管理工具是哪个? 维基上有个很全的列表: https://en.wikipedia.org/wiki/Comparison_of_database_tools   1. ph ...

  4. Linux 、AIX环境下查看oracle配置信息(service_name、SID、tnsname)。

    SID: echo $ORACLE_SID service_name: sqlplus / as sysdba; show parameter instance_name; show paramete ...

  5. 反射中 invoke方法 getMethod方法 getClass()方法

    package com.swift; import java.util.*; import java.lang.reflect.*; public class ReflectDemo { public ...

  6. 原型与原型继承demo

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. numpy学习(一)

    numpy数据类型 # numpy创建对象,numpy创建的对象是n阶矩阵,类似python中列表的嵌套 nd = np.array([[1,2,3,4,5],[2,3,4,6,5]])nd 结果: ...

  8. chrome浏览器跳过(忽略)所有的js断点

    在调试程序时我们经常通过打断点的方式来跟踪代码的执行流程,所以可能会在很多时候打很多断点,当我们知道了程序大概的执行流程之后,这时候断点就不太需要了.但是我们又不想马上把所有的断点清除掉,因为我们打的 ...

  9. ActiveXObject

    只有IE浏览器才支持这个构造函数,可以用这个来判断,当前是否为IE浏览器 var isIE=!!window.ActiveXObject; 在IE的不同版本下,要创建XHR对象,也需要通过这个构造函数 ...

  10. 《Spring源码深度解析》第三章 默认标签的解析

    上一章提到了,默认标签和自定义标签要分开解析.本章重点介绍默认标签的解析.在 DefaultBeanDefinitionDocumentReader 中: private void parseDefa ...