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. mac层到ath9k层,ath9k层到硬件层

    如上图,整个 mac 层分成两个部分——UMAC 和 LMAC.LMAC 分成 MAC 下半部分和硬件抽象层. 硬件抽象层和ath9k层的连接 在hw.h中的函数struct ath_hw_ops() ...

  2. Nginx超时配置

    Nginx超时配置 1.client_header_timeout 语法client_header_timeout time 默认值60s 上下文http server 说明 指定等待client发送 ...

  3. Linux常用命令-----------------磁盘挂载命令

    磁盘挂载: [root@sdw1 ~]# mkfs.ext4 /dev/vdb[root@sdw1 ~]# blkid /dev/vdb >> /etc/fstabvi /etc/fsta ...

  4. 【思维题 费用流 技巧】bzoj5403: marshland

    主要还是网络流拆点建图一类技巧吧 Description JudgeOnline/upload/201806/1(4).pdf 题目分析 第一眼看到这题时候只会把每个点拆成4个方向:再强制定向连边防止 ...

  5. (68)zabbix windows性能计数器使用详解

    概述 windows下的性能计数器让zabbix监控更加轻松,直接获取性能计数器的数值即可完成windows监控.性能计数器如下:   1 perf_counter["\Processor( ...

  6. H5 移动APP - 面包店

    使用jquerymobile.html5.css3实现移动APP 流程图 打包 用hbuilder实现打包 效果截图展示 图2-1 APP图标 图2-2 主页 图2-3 面包列表&详细信息 图 ...

  7. JS正则表达式学习总结

    JS正则:java RegExp对象,它是对字符串执行模式匹配的强大工具.运用最多的就是在输入处验证输入的字符串是否合法,指定用户输入字符串的格式. 定义方法: 1:直接量语法:var re=/pat ...

  8. 14Shell脚本—判断语句

    判断语句 Shell脚本中的条件测试语法可以判断表达式是否成立,若条件成立则返回数字0,否则便返回其他随机数值. 条件测试语法的执行格式为 [ 条件表达式 ],切记,条件表达式两边均应有一个空格. 条 ...

  9. Python基础——字符串操作

    运算符 加(+)   str2="hello"+"python" print(str2) 乘(*)   str1="hello python" ...

  10. 关于dispatch_sync死锁问题

    首先,我们来看下下面一个例子: 代码:(串行队列里同步线程嵌套)     NSLog(@"haha");     dispatch_queue_t queue = dispatch ...