C

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,d使等式成立,并且k最大,A,B是C进制的;很简单, k = (A - d)/B;
k最大, k = floor(A/B);进制转化成10进制就好了
代码:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
bool is_digit(char c){
if(c >= '' && c <= '')
return true;
return false;
}
int cj(char *s, int C){
int x = ;
// cout << s << " " << C << endl;
for(int i = ; s[i]; i++){
int t = is_digit(s[i]) ? s[i] - '':s[i] - 'a' + ;
x = x * C + t;
}
// cout << "x = " << x << endl;
return x;
}
int main(){
int T;
scanf("%d", &T);
char s[], s1[];
while(T--){
int A, B, C;
scanf("%s%s%d", s, s1, &C);
A = cj(s, C);
B = cj(s1, C);
int r;
r = A/B;
int l = A - r * B;
printf("(%d,%d)\n", r,l);
}
return ;
}
H

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

Description

Now you are given one non-negative integer n in 10-base notation, it will only contain digits ('0'-'9'). You are allowed to choose 2 integers i and j, such that: i!=j, 1≤i<j≤|n|, here |n| means the length of n’s 10-base notation. Then we can swap n[i] and n[j].

For example, n=9012, we choose i=1, j=3, then we swap n[1] and n[3], then we get 1092, which is smaller than the original n.

Now you are allowed to operate at most M times, so what is the smallest number you can get after the operation(s)?

Please note that in this problem, leading zero is not allowed!

Input

The first line of the input contains an integer T (T≤100), indicating the number of test cases.

Then T cases, for any case, only 2 integers n and M (0≤n<10^1000, 0≤M≤100) in a single line.

Output

For each test case, output the minimum number we can get after no more than M operations.

Sample Input

3 9012 0 9012 1 9012 2

Sample Output

9012 1092 1029
题解:
水贪心,交换不能出现前缀0;
代码:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
const int MAXN = ;
char s[MAXN];
int main(){
int T, M;
scanf("%d", &T);
while(T--){
scanf("%s%d", s, &M);
for(int i = ; s[i]; i++){
for(int j = i + ; s[j]; j++){
char pos = i;
if(M <= )break;
if(i == ){
if(s[j] != '' && s[j] < s[pos]){
pos = j;
}
}
else{
if(s[j] < s[pos]){
pos = j;
}
}
if(pos != i){
swap(s[pos], s[i]);
M--;
}
}
}
printf("%s\n", s);
}
return ;
}

FZU 2102 Solve equation(水,进制转化)&& FZU 2111(贪心,交换使数字最小)的更多相关文章

  1. ACM: FZU 2102 Solve equation - 手速题

     FZU 2102   Solve equation Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  2. FZOJ 2102 Solve equation

                                                                                                        ...

  3. 【风马一族_C】进制转化

    #include "stdio.h" #include "Math.h" #define number 50 //设置数组的长度 int num10; //十进 ...

  4. c语言进制转化

    #include <stdio.h> // 进制转化 int main(void) { ; ; int i3 = 0x32C; printf( printf( printf("十 ...

  5. 编码/解码和进制转化工具hURL

    编码/解码和进制转化工具hURL   在安全应用中,各种编码方式被广泛应用,如URL编码.HTML编码.BASE64等.而在数据分析时候,各种进制的转化也尤为频繁.为了方便解决这类问题,Kali Li ...

  6. HDU5050:Divided Land(大数的进制转化与GCD)

    题意:给定大数A和B,求gcd.所有数字都是二进制. 思路:先输入字符串,再转化为大数,然后用大数的gcd函数,最后转化为字符串输出. 利用字符串和大数转化的时候可以声明进制,就很舒服的完成了进制转化 ...

  7. python数据结构:进制转化探索

    *********************************第一部分*************************************************************** ...

  8. 《N诺机试指南》(五)进制转化

    进制转化类题目类型: 代码详解及注释解答:  //进制转化问题 #include <bits/stdc++.h> using namespace std; int main(){ // 1 ...

  9. P1017进制转化

    P1017进制转化 也不知道为啥,这么简单的题困扰了我这么长时间 #include<cstdio> using namespace std; int m; //被除数= 除数*商 + 余数 ...

随机推荐

  1. Android应用盈利广告平台的嵌入方法详解

    一.如何学习Android  android开发(这里不提platform和底层驱动)你需要对Java有个良好的基础,一般我们用Eclipse作为开发工具.对于过多的具体知识详细介绍我这里不展开,我只 ...

  2. 临时解决linux下time wait问题

     通过 netstat  -anp | grepTIME_WAIT | wc -l 命令查看数量,发现TIME_WAIT的连接数量超过了阈值   1.初步怀疑是程序没有关闭连接,codereview了 ...

  3. Silverlight Visifire控件应用去水印

    版本几之前可以用属性直接去掉水印: chart.Watermark = false; 现在我用的会报错,已过时,在网上查了写资料,解决办法如下: 一.很多人都是利用摭罩的办法,定位到水印显示的地方,建 ...

  4. OpenGL ES 2.0 混合

    混合技术 混合技术就是将俩个片元调和,主要用于将通过各项测试准备进入帧缓冲的片元(源片元)与原有片元按照设定的比例加权计算出最终片元的颜色值. OpenGL ES 2.0中是通过设置混合因子来指定两个 ...

  5. C# 数据实现设计模式

    一个人没事,写了一个底层数据实现读取设计模式,个人觉得还是蛮好扩展,里面有不足的地方希望大家给予指导.话不多说先看个图吧!图可能不正规,伤害了你的眼睛见谅.有图有真相 其实这个设计模式,就是一个简单的 ...

  6. [转]shell中 source命令即点空格后面再跟可执行文件的说明

    这里记录的是在一个shell脚本里面使用. ./file.sh 和./file.sh 的区别,本文参考了http://www.lslnet.com/linux/dosc1/39/linux-28353 ...

  7. Python 学习日记(第二周)

    从这周开始我就正式学习Python 语言了.以后每周都会有一篇有关于学习Python的见闻与大家分享! Python的安装 学习的第一步首先要有一个运行的环境.所以接下来介绍一下安装的步骤. 通过Py ...

  8. django-filter 使用Filter来筛选你的数据

    django-filter Django-filter is a generic, reusable application to alleviate writing some of the more ...

  9. Django的 select_related 和 prefetch_related 函数对 QuerySet 查询的优化(一)

    在数据库有外键的时候,使用 select_related() 和 prefetch_related() 可以很好的减少数据库请求的次数,从而提高性能.本文通过一个简单的例子详解这两个函数的作用.虽然Q ...

  10. [Codeforces Round #186 (Div. 2)] B. Ilya and Queries

    B. Ilya and Queries time limit per test 2 seconds memory limit per test 256 megabytes input standard ...