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. Composer 基本指令操作使用

    Composer 基本指令操作使用 註: 若 composer.phar 改名為 composer, 請自行將 "php composer.phar" 替換成 "comp ...

  2. android实现计算器功能

    设计一个简单的计算器. 第一个Activity的界面. 第二个Activity显示算式和计算结果. 第一个Activity代码: import android.app.Activity; import ...

  3. UITableView滑动按钮的操作

    一.开题  首先先创建工程, 创建工程的步骤就不一一介绍了, 前面有提过, 接下来是要在VC上创建一个tableview当然你也可以选择一个类继承于UITableView两者都可以, 这要看个人喜欢了 ...

  4. 验证docker的Redis镜像也存在未授权访问漏洞

    看到了这篇老外的博客:Over 30% of Official Images in Docker Hub Contain High Priority Security Vulnerabilities于 ...

  5. python 之 Paramiko学习

    paramiko模块,基于SSH用于连接远程服务器并执行相关操作. 一.安装 pip3 install paramiko 二.使用 SSHClient 用于连接远程服务器并执行基本命令 基于用户名密码 ...

  6. 第一篇文章-VS的Local DB数据库连接失败,创建实例失败的解决方案

    用了很久的LocalDB了,不用装那么多的SQL组件感觉很不错,前不久调试代码碰到一个问题 ,VS突然就连接不上LocalDB了,琢磨了一下午,其实有个很简单的方法. 第一步,先找到SQL Local ...

  7. Effective C++ 第二版 5)new和delete形式 6) 析构函数里的delete

    内存管理 1)正确得到: 正确调用内存分配和释放程序; 2)有效使用: 写特定版本的内存分配和释放程序; C中用mallco分配的内存没有用free返回, 就会产生内存泄漏, C++中则是new和de ...

  8. 对面向对象程序设计(OOP)的认识

    前言 本文主要介绍面向对象(OO)程序设计,以维基百科的解释: 面向对象程序设计(英语:Object-oriented programming,缩写:OOP),指一种程序设计范型,同时也是一种程序开发 ...

  9. mysql和mysqli的区别

    看书.看视频的时候一直没有搞懂mysqli和mysql到底有什么区别.于是今晚“谷歌”一番,整理一下.需要的朋友可以参考下.   一: PHP-MySQL 是 PHP 操作 MySQL 数据库最原始的 ...

  10. PHP命名空间(Namespace)的使用详解(转)

    对于命名空间,官方文档已经说得很详细[查看],我在这里做了一下实践和总结. 命名空间一个最明确的目的就是解决重名问题,PHP中不允许两个函数或者类出现相同的名字,否则会产生一个致命的错误.这种情况下只 ...