FZOJ 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
equation in Base 10.
Sample Input
2bc 33f 16
123 100 10
1 1 2
Sample Output
(1,23)
(1,0)
#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的更多相关文章
- ACM: FZU 2102 Solve equation - 手速题
FZU 2102 Solve equation Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- FZU 2102 Solve equation(水,进制转化)&& FZU 2111(贪心,交换使数字最小)
C Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Pra ...
- 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新生 ...
- FZU2102Solve equation
Problem 2102 Solve equation Accept: 881 Submit: 2065 Time Limit: 1000 mSec Memory Limit : 3276 ...
- 最小二乘法多项式拟合的Java实现
背景 由项目中需要根据一些已有数据学习出一个y=ax+b的一元二项式,给定了x,y的一些样本数据,通过梯度下降或最小二乘法做多项式拟合得到a.b,解决该问题时,首先想到的是通过spark mllib去 ...
- 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 ...
- 机器人关节空间轨迹规划--S型速度规划
关节空间 VS 操作空间 关节空间与操作空间轨迹规划流程图如下(上标$i$和$f$分别代表起始位置initial和目标位置final): 在关节空间内进行轨迹规划有如下优点: 在线运算量更小,即无需进 ...
- 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 ...
- Matlab-5:牛顿迭代法工具箱
function [f,L]=Newton(f,a) %this is newton teration whic is used for solving implicit One-dimensiona ...
随机推荐
- mongodb 导入导出
F:\Mongodb\bin>mongoexport.exe -h localhost:27017 -d proxy_db -c proxy_tb -o f:/p1.json 导出 -h 服务器 ...
- Java(面试题):字符串截取
在Java中,字符串“abcd”与字符串“ab你好”的长度是一样,都是四个字符. 但对应的字节数不同,一个汉字占两个字节. 定义一个方法,按照指定的字节数来取子串. 如:对于“ab你好”,如果取三个字 ...
- java基础——随机数问题
/** * 要求:随机打印50个随机(4-10长度)的字符串,要求字符串包含的范围是所有的英文字母包含大小写和数字, * 按照编码顺序排序,每行打印4个,要求首字符对齐 * @author fanyu ...
- 实现HTTP文件下载
[原文:http://www.jb51.net/article/89958.htm] HTTP实现文件下载时,只要在服务器设置好相关响应头,并使用二进制传输文件数据即可,而客户端(浏览器)会根据响应头 ...
- 从屏幕截取一块区域,将其赋给imageView
UIGraphicsBeginImageContext(self.bounds.size); [self.layerrenderInContext:UIGraphicsGetCurrentContex ...
- 【转】Windows 邮件槽(MailSlot)
Windows 邮件槽(MailSlot) 来自<Windows网络编程第二版 中文版> 优点:通过网络,将一条消息广播给一台或多台计算机. 缺点:只允许从客户机到服务器,建立一种不可 ...
- CPL学习笔记(一)
整型 计算机的内存的基本单位是位(bit),可以将其看作电子开关,可以开,表示1:也可以关表示0. 字节(byte)通常指八位的内存单元. 8bit=1byte=1B; 1KB=1024B; 1M=1 ...
- proc_info_list
内核中每种处理器架构抽象为一个proc_info_list结构体,在arch/arm/include/asm/procinfo.h中定义, struct proc_info_list { unsign ...
- ProC第一弹
编译pro*c 的makefile例子 原来只需在makefile中追加include $(ORACLE_HOME)/precomp/lib/env_precomp.mk,其他一切按照makefile ...
- hdu-2063 过山车(二分图)
Time limit1000 ms Memory limit32768 kB RPG girls今天和大家一起去游乐场玩,终于可以坐上梦寐以求的过山车了.可是,过山车的每一排只有两个座位,而且还有条不 ...