FZU 2102 Solve equation(水,进制转化)&& FZU 2111(贪心,交换使数字最小)
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
Sample Output
#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 ;
}
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
Sample Input
Sample Output
#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(贪心,交换使数字最小)的更多相关文章
- ACM: FZU 2102 Solve equation - 手速题
FZU 2102 Solve equation Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- FZOJ 2102 Solve equation
...
- 【风马一族_C】进制转化
#include "stdio.h" #include "Math.h" #define number 50 //设置数组的长度 int num10; //十进 ...
- c语言进制转化
#include <stdio.h> // 进制转化 int main(void) { ; ; int i3 = 0x32C; printf( printf( printf("十 ...
- 编码/解码和进制转化工具hURL
编码/解码和进制转化工具hURL 在安全应用中,各种编码方式被广泛应用,如URL编码.HTML编码.BASE64等.而在数据分析时候,各种进制的转化也尤为频繁.为了方便解决这类问题,Kali Li ...
- HDU5050:Divided Land(大数的进制转化与GCD)
题意:给定大数A和B,求gcd.所有数字都是二进制. 思路:先输入字符串,再转化为大数,然后用大数的gcd函数,最后转化为字符串输出. 利用字符串和大数转化的时候可以声明进制,就很舒服的完成了进制转化 ...
- python数据结构:进制转化探索
*********************************第一部分*************************************************************** ...
- 《N诺机试指南》(五)进制转化
进制转化类题目类型: 代码详解及注释解答: //进制转化问题 #include <bits/stdc++.h> using namespace std; int main(){ // 1 ...
- P1017进制转化
P1017进制转化 也不知道为啥,这么简单的题困扰了我这么长时间 #include<cstdio> using namespace std; int m; //被除数= 除数*商 + 余数 ...
随机推荐
- 【编程范式】汇编解释swap方法
先要熟悉一些汇编的基本知识: 1.SP是什么? SP是堆栈寄存器,在调用子程序时,都会用到,保存原来程序的环境使用,如各个寄存器的内容,最重要的是,调用返回时程序的运行指令地址,这是由调用时将返回地址 ...
- UVA 825 Walking on the Safe Side(记忆化搜索)
Walking on the Safe Side Square City is a very easy place for people to walk around. The two-way ...
- java 图片 批量 压缩 +所有压缩
/* oldsrc : 原图片地址目录 如 'd:/' newsrc : 压缩后图片地址目录 如 'e:/' widthdist,heightdist : 压缩后的宽和高 ...
- JavaScript学习笔记:检测数组方法
检查数组的方法 很多时候我们需要对JavaScript中数据类型(Function.String.Number.Undefined.Boolean和Object)做判断.在JavaScript中提供了 ...
- VCS仿真生成vpd文件(verilog)
VCS仿真生成vpd文件(verilog) 一.环境与文件 Linux平台 csh环境 VCS 64bit 代码文件请参考<一个简单的Verilog计数器模型> 二.开始仿真 1.com ...
- 高可用集群(HA)配置
高可用集群(HA) 1. 准备工作 HA的心跳监测可以通过串口连接监测也可以通过网线监测,前者需要服务器有一个串口,后者需要有一个空闲网卡.HA架构中需要有一个共享的存储设备首先需要在两台机器上安装m ...
- css画下图
通常我看到这种效果,都是直接ps解决,但是不断重申性能的今天,显然不适应时代的需求啊! 今天看到群里有人问这种效果怎么做了,我在思考的时候,有人已经给出答案了: 我就测试了一下,发现确实可以实现,总结 ...
- ASP.NET批量下载服务器端指定目录文件
//遍历服务器指定文件夹下的所有文件 string path = "uploads/Image/"; string serverPath = Server.MapPath(path ...
- IIS 7管理API——Microsoft.Web.Administration介绍
原文:http://www.cnblogs.com/dflying/archive/2006/04/17/377276.html 本文翻译整理自Carlos Aguilar Mares的blog文章: ...
- call()与apply()传参需要注意的一点
call()与apply()是用来改变函数体内的this指向,第一个参数是调用函数的母对象,他是调用上下文,函数体内通过this来获得对它的引用,换句话说就是第一参数===函数中的this. 但是如下 ...