FZU2102Solve equation
Accept: 881 Submit: 2065
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
Sample Input
Sample Output
题目意思很好懂吧,然而做的时候就卡在了进制转换这,特意去百度了一下怎么转10进制;
网上是这样给的:
假如一个数abcdef,是x进制数,转10进制就是a*x^5+b*x^4+c*x^3+d*x^2+e*x^1+f*x^0;看懂了吧,当时还真这样用for循环遍历了一遍,还真对,运行结果及其他测试样例也都没错,但这思路代码活生生CE了6遍;
CE:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<ctype.h>
using namespace std;
int main()
{
int t,a,b,c,x1,x2;
char aa[55],bb[55];
scanf("%d",&t);
while(t--)
{
memset(aa,'0',sizeof(aa));
memset(bb,'0',sizeof(bb));
a=b=0;
scanf("%s%s%d",aa,bb,&c);
x1=strlen(aa);
x2=strlen(bb);
int x11=x1,x22=x2;
if(c==10)
{
for(int i=0;i<x1;i++)
a=a*10+(aa[i]-'0');
for(int i=0;i<x2;i++)
b=b*10+(bb[i]-'0');
}
else
{
for(int i=0;i<x1;i++)
{
if(islower(aa[i]))
a+=(aa[i]-'a'+10)*pow(c,x11-i-1);
else
a+=(aa[i]-'0')*(pow(c,(x11-i-1)));
}
for(int i=0;i<x2;i++)
{
if(islower(bb[i]))
b+=(bb[i]-'0'+10)*(pow(c,(x22-i-1)));//记得pow好像适用于double,可能要用pow(double(c),_);
else
b+=(bb[i]-'0')*(pow(c,(x22-i-1)));
}
}
int k=a/b,d=a-k*b;
printf("(%d,%d)\n",k,d);
}
return 0;
}
就这样浪费了一个水题;
看以AC的代码发现他们都是这样转10进制的: 字符串a输入,假如长度x,是c进制数,那么转10进制 int aa=0;
(1) for(i=0;i<x;i++)
aa=aa*10+(aa[i]-'0')//字符串本身代表的就是10进制数;
(2)
for(i=0;i<x;i++)
aa=aa*10+(aa[i]-'a'+10)//字符串本身代表的不是10进制数,,,,,百度上怎么没有,,亿脸懵逼;;;
AC:
<span style="font-size:18px;">#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<ctype.h>
using namespace std;
int main()
{
int t,a,b,c,x1,x2;
char aa[55],bb[55];
scanf("%d",&t);
while(t--)
{
a=b=0;
scanf("%s%s%d",aa,bb,&c);
x1=strlen(aa);
x2=strlen(bb);
for(int i=0; i<x1; i++)
{
if(islower(aa[i]))
a=a*c+(aa[i]-'a')+10;
else
a=a*c+(aa[i]-'0');
}
for(int i=0; i<x2; i++)
{
if(islower(bb[i]))
b=b*c+(bb[i]-'a')+10;
else
b=b*c+(bb[i]-'0');
}
int k=a/b,d=a-k*b;
printf("(%d,%d)\n",k,d);
}
return 0;
}</span>
FZU2102Solve equation的更多相关文章
- CodeForces460B. Little Dima and Equation
B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input s ...
- ACM: FZU 2102 Solve equation - 手速题
FZU 2102 Solve equation Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- HDU 5937 Equation
题意: 有1~9数字各有a1, a2, -, a9个, 有无穷多的+和=. 问只用这些数字, 最多能组成多少个不同的等式x+y=z, 其中x,y,z∈[1,9]. 等式中只要有一个数字不一样 就是不一 ...
- coursera机器学习笔记-多元线性回归,normal equation
#对coursera上Andrew Ng老师开的机器学习课程的笔记和心得: #注:此笔记是我自己认为本节课里比较重要.难理解或容易忘记的内容并做了些补充,并非是课堂详细笔记和要点: #标记为<补 ...
- CF460B Little Dima and Equation (水题?
Codeforces Round #262 (Div. 2) B B - Little Dima and Equation B. Little Dima and Equation time limit ...
- Linear regression with multiple variables(多特征的线型回归)算法实例_梯度下降解法(Gradient DesentMulti)以及正规方程解法(Normal Equation)
,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, , ...
- ACM:HDU 2199 Can you solve this equation? 解题报告 -二分、三分
Can you solve this equation? Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Su ...
- [ACM_数学] Counting Solutions to an Integral Equation (x+2y+2z=n 组合种类)
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27938#problem/E 题目大意:Given, n, count the numbe ...
- hdu 2199 Can you solve this equation?(二分搜索)
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
随机推荐
- jquery选择器 选择除当前点击元素外所有的元素
问题: 多个select选择,如果已选择某些value ,该value不可再选 思路: 点击当前元素,js列出除当前元素外所有的元素 当前解决办法: function symbolDefine(ob ...
- Mysql中的索引问题
索引的用途 提高查询的效率,相当于在字典中建立的字母表或者偏旁部首表,这样查询当然比一行一行查询要快的多 每个存储引擎可以建立索引的长度是不一样的,但每个表至少支持16个索引,总的索引长度至少为256 ...
- DNS正、反向解析+负载均衡+智能DNS+密钥认证
主机名 IP 软件包 系统版本 内核版本 实验环境 master 192.168.30.130 bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6 bind-chroot.x8 ...
- android开发学习 ------- 【转】EventBus的学习理解
EventBus是一个Android端优化的publish/subscribe消息总线,简化了应用程序内各组件间.组件与后台线程间的通信. 比如请求网络,等网络返回时通过Handler或Broadca ...
- C# winform 创建快捷方式
using System;using IWshRuntimeLibrary;using System.IO; namespace UavSystem.Common{ public class S ...
- NodeJS&&前端思考
做大型软件(工程化): 1.测试相关 tdd / bdd 测试覆盖率 2.规范化 standard.各种 lint.hint 3.构建相关 gulp.grunt.webpack,大量插件 4.生成器 ...
- mysql多表查询20题
+-------------------+| Tables_in_dapeng3 |+-------------------+| class || course || s1 || score || s ...
- Android模板制作
本文详细介绍模板相关的知识和如何制作Android模版及使用,便于较少不必要的重复性工作.比如我在工作中如果要创建一个新的模块,就不要需要创建MVP相关的几个类:Model.View.Presente ...
- 关于Android发送短信获取送达报告的问题
最近公司开发一个项目,要求app能够发送短信并获取送达报告.这本不是一个什么难题,实现这一功能的代码一搜一大把,那么这么简单的一个问题,为什么我要在这里提出来呢?那是因为我在写代码的时候掉入了一个坑, ...
- JD IPO address by liuqiangdong
Ladies and gentlemen, Good evening.I'd rather use english, not mandarin.Because during the road show ...