ACM: 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
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 - 手速题的更多相关文章
- FZU 2102 Solve equation(水,进制转化)&& FZU 2111(贪心,交换使数字最小)
C Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Pra ...
- FZOJ 2102 Solve equation
...
- 河南省acm第九届省赛--《表达式求值》--栈和后缀表达式的变形--手速题
表达式求值 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 假设表达式定义为:1. 一个十进制的正整数 X 是一个表达式.2. 如果 X 和 Y 是 表达式,则 X+Y, ...
- ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Gym 101047B Renzo and the palindromic decoration Time Limit:2000MS Memory Limit:65536KB 64 ...
- ACM: FZU 2110 Star - 数学几何 - 水题
FZU 2110 Star Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Pr ...
- Codeforces 987A. Infinity Gauntlet(手速题,map存一下输出即可)
解法: 1.先将对应的字符串存入map. 2.然后将输入的串的second置为空. 3.输出6-n,输出map中的非空串. 代码: #include <bits/stdc++.h> usi ...
- Contest - 2014 SWJTU ACM 手速测试赛(2014.10.31)
题目列表: 2146 Problem A [手速]阔绰的Dim 2147 Problem B [手速]颓废的Dim 2148 Problem C [手速]我的滑板鞋 2149 Problem D [手 ...
- fzu 1909 An Equation(水题)
题目链接:fzu 1909 An Equation 典型的签到题. #include <stdio.h> #include <string.h> bool judge(int ...
- 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新生 ...
随机推荐
- html5新增的主体结构元素
1. article 主体结构元素 通常是一篇文章.一个页面.一个独立完整的内容模块一般会带个标题,并放在 header 标签中,article 元素可以互相嵌套,使用频率极高,强调独立性,多注意下 ...
- Symbiont
http://www.weiyangx.com/209230.html Symbiont,Credit Suisse与R3携手革新贷款数据验证环节Symbiont, Credit Suisse and ...
- 初探微信小程序
摘要 最近闲下来了,就准备了解下微信小程序的内容.首先从目录结构开始吧. 创建项目 工具下载:https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/do ...
- 【09-03】java泛型学习笔记
静态方法的泛型 /** * @description 静态方法的泛型无法使用类定义的泛型,因为类在实例化时才确定具体的泛型类,因此静态方法要使用泛型需要使用泛型方法的方式 */ public clas ...
- 2、HTML 基础知识
一.HTT(PHyper Text Markup Language)即超文本语言. 特点: 1.通过标签来定义的语言,代码都是由标签所组成 2.不区分大小写 3.由<html>开始< ...
- 手动封装js原生XMLHttprequest异步请求
Code Object.extend =function(targetObj,fnJson){ //扩展方法,类似于jQuery的$.extend,可以扩展类的方法,也可以合并对象 for(var f ...
- XML格式示例 与 XML操作(读取)类封装
header('Content-Type: text/xml'); <?xml version="1.0" encoding="utf-8" standa ...
- 如何查看、修改Linux的系统时间
如题: 如何修改Linux的系统时间? date -s 05/27/2011 date -s 10:24:00 clock -w 就这三条命令就OK了! 查看/修改Linux时区和时间 一.时区 1. ...
- java基础知识(一)数据类型(上)
java的数据类型 由上图,java的数据类型分为基本数据类型.引用数据类型两大类. 1.基本数据类型 与c不同,java的各种数据类型占有固定长度的内存,与具体的软硬件平台无关:另外,每种数据类型都 ...
- HeapSort 堆排序 基于伪代码实现
此文原创, http://www.cnblogs.com/baokang/p/4735431.html ,禁止转载 GIF 动态图 伪代码 /* From Wikipedia, the free en ...