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; //被除数= 除数*商 + 余数 ...
随机推荐
- 用户控件(.ascx)与<ul><li>以及<a>布局之小结
用户控件(.ascx)与<ul><li>以及<a>布局 小结 一.用户控件(.ascx) 1.aspx是浏览器直接访问的页面,而ascx是用户控件,一般是用来重用. ...
- C++类訪问控制及继承
一.C++类的訪问控制有三类:public,protected和private. 类訪问控制符 类成员可被哪些对象訪问 public 1.类的成员函数.2.类对象.3.友元.4.子类成员函数 prot ...
- Difference between enabled and userInteractionEnabled properties
I read through the documentation, and here are my findings. UIButton inherits from UIControl the boo ...
- CSS元素 之 float
1. float 设计的初衷 Float 设计的初衷是为了文字环绕的效果 使得文字可以围绕着 图片.就像下面这样 2. float 的包裹和 破坏 A) 包裹性 和 破坏性 例如下图 我们原本是希 ...
- How to center anything with css
1. 绝对居中定位技术 我经常用margin:0 auto来实现水平居中,而一直认为margin:auto不能实现垂直居中……实际上,实现垂直居中仅需要声明元素高度和下面的CSS 优点: 缺点: 1 ...
- .NET基础拾遗(6)特性
1 神马是特性?如何自定义一个特性? (1)特性是什么 特性是一个对象,可以加载到程序集及程序集的对象中,这些对象包括 程序集本身.模块.类.接口.结构.构造函数.方法.方法参数等,加载了特性 ...
- oc随笔六:字典
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...
- 费马小定理&欧拉定理
在p是素数的情况下,对任意整数x都有xp≡x(mod p).这个定理被称作费马小定理其中如果x无法被p整除,我们有xp-1≡1(mod p).利用这条性质,在p是素数的情况下,就很容易求出一个数的逆元 ...
- memcached介绍及基本使用
一:概念 memcached是LiveJournal旗下Danga Interactive 公司的Brad Fitzpatric 为首开发的一款软件.现在已成为mixi,hatena,facebook ...
- 如何让你的 footer 总是在浏览器底部无论什么分辨率无论什么浏览器?
一个可以用的CSS驱动的可粘在底部的Footer 我们曾经都或多或少的试过用CSS来把Footer固定在底部的经理,但是他们总是不能正常的粘在底部,不是吗?可喜的是,痛苦的研究如何让footer粘在底 ...