FZU 2102   Solve equation

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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 ; 最大,直接就是 k = A / B , d = A % B ; AC代码:
#include"algorithm"
#include"iostream"
#include"cstring"
#include"cstdlib"
#include"cstdio"
#include"string"
#include"vector"
#include"stack"
#include"queue"
#include"cmath"
#include"map"
using namespace std;
typedef long long LL ;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define FK(x) cout<<"["<<x<<"]\n"
#define memset(x,y) memset(x,y,sizeof(x))
#define memcpy(x,y) memcpy(x,y,sizeof(x))
#define bigfor(T) for(int qq=1;qq<= T ;qq++) const int MX=50; int main() {
int T;
LL c;
char a[50],b[50];
scanf("%d",&T);
bigfor(T) {
scanf("%s %s %I64d",a,b,&c);
int la=strlen(a);
int lb=strlen(b);
LL aa=0,bb=0;
LL m=1;
for(int i=la-1; i>=0; i--) {
if(a[i]<='9'&&a[i]>='0')aa+=(a[i]-'0')*m;
if(a[i]<='f'&&a[i]>='a')aa+=(a[i]-'a'+10)*m;
m*=c;
}
m=1;
for(int i=lb-1; i>=0; i--) {
if(b[i]<='9'&&b[i]>='0')bb+=(b[i]-'0')*m;
if(b[i]<='f'&&b[i]>='a')bb+=(b[i]-'a'+10)*m;
m*=c;
}
LL ans1,ans2;
ans1=aa/bb;
ans2=aa%bb;
printf("(%I64d,%I64d)\n",ans1,ans2);
}
return 0;
}

  


ACM: FZU 2102 Solve equation - 手速题的更多相关文章

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

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

  2. FZOJ 2102 Solve equation

                                                                                                        ...

  3. 河南省acm第九届省赛--《表达式求值》--栈和后缀表达式的变形--手速题

    表达式求值 时间限制:1000 ms | 内存限制:65535 KB 难度:3   描述 假设表达式定义为:1. 一个十进制的正整数 X 是一个表达式.2. 如果 X 和 Y 是 表达式,则 X+Y, ...

  4. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  5. ACM: FZU 2110 Star - 数学几何 - 水题

     FZU 2110  Star Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u  Pr ...

  6. Codeforces 987A. Infinity Gauntlet(手速题,map存一下输出即可)

    解法: 1.先将对应的字符串存入map. 2.然后将输入的串的second置为空. 3.输出6-n,输出map中的非空串. 代码: #include <bits/stdc++.h> usi ...

  7. Contest - 2014 SWJTU ACM 手速测试赛(2014.10.31)

    题目列表: 2146 Problem A [手速]阔绰的Dim 2147 Problem B [手速]颓废的Dim 2148 Problem C [手速]我的滑板鞋 2149 Problem D [手 ...

  8. fzu 1909 An Equation(水题)

    题目链接:fzu 1909 An Equation 典型的签到题. #include <stdio.h> #include <string.h> bool judge(int ...

  9. 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新生 ...

随机推荐

  1. mod-mono

    http://go-mono.com/config-mod-mono/  配置文件生成器 Mono remote debugging from Visual Studio http://stackov ...

  2. centos7删除自带openjdk

    一些开发版的centos会自带jdk,我们一般用自己的jdk,把自带的删除.先看看有没有安装java -version [root@java-test-01 ~]# java -version ope ...

  3. winform 多线程编程

    参考资料: WinForm中新开一个线程操作 窗体上的控件(跨线程操作控件) c# 使用定时器Timer

  4. Daily Scrum Meeting ——TenthDay

    一.Daily Scrum Meeting照片 二.Burndown Chart 新增了几个issues 三.项目进展 1.完成了登录界面与管理员和发布者界面的整合. 2.活动发布者界面的完成 四.问 ...

  5. tornado 重定向404(方法不对)

    application = tornado.web.Application(url_wrapper([ (r"", include('app.views.web_services. ...

  6. python des ecb 加密 demo

    # -*- coding:utf-8 -*- from pyDes import * def hexString2bytes(src): ret =[] for i in range(len(src) ...

  7. PHP 打印调试信息

    1.将输出的数组存入文件,比如debug_trace()的输出: $debug_info = print_r(debug_backtrace(),true); file_put_contents(&q ...

  8. JVM内存管理------垃圾搜集器简介

    引言 上一章我们已经探讨过GC的各个算法,那么垃圾搜集器是什么呢? 通俗的讲,使用编程语言将算法实现出来,产生的程序就是垃圾搜集器了.既然谈到了编程语言的实现,那么在讨论垃圾搜集器的时候,就已经涉及到 ...

  9. Memcache 内存分配策略和性能(使用)状态检查

    前言: 一直在使用Memcache,但是对其内部的问题,如它内存是怎么样被使用的,使用一段时间后想看看一些状态怎么样?一直都不清楚,查了又忘记,现在整理出该篇文章,方便自己查阅.本文不涉及安装.操作. ...

  10. node07-http

    目录:node01-创建服务器 node02-util node03-events node04-buffer node05-fs node06-path node07-http node08-exp ...