摘要:
A:找出给出数的娇小数并输出其阶乘。
B:给出两个字符串,比较得出一个字符串成为另一个串的子串需要修改的最少字母数量和位置。
原题目:
A题 :
http://codeforces.com/problemset/problem/822/A
B题 : http://codeforces.com/problemset/problem/822/B
......
Leha came up with a task for himself to relax a little. He chooses two integers A and B and then calculates the greatest common divisor of integers "A factorial" and "B factorial". Formally the hacker wants to find out GCD(A!, B!). It's well known that the factorial of an integer x is a product of all positive integers less than or equal to x. Thus x! = 1·2·3·...·(x - 1)·x. For example 4! = 1·2·3·4 = 24. Recall that GCD(x, y) is the largest positive integer q that divides (without a remainder) both x and y.
........
1
Input
2
The first and single line contains two integers A and B (1 ≤ A, B ≤ 109, min(A, B) ≤ 12).
1
Output
2
Print a single integer denoting the greatest common divisor of integers A! and B!.
Example
题目理解:
A:直接do,阶乘可以使用递归
B:暴力比较出最少更改的匹配位置,纪录;暴力完后按纪录的位置重新比较输出。
日期:
2017/7/8
代码:
A
1
2
3
using namespace std;
4
5
int multip(int n){
6
if(n==0) return 1;
7
return n*multip(n-1);
8
}
9
10
int main(){
11
int a,b;
12
scanf("%d%d",&a,&b);
13
printf("%d",multip(min(a,b)));
14
return 0;
15
}
B
1
2
3
4
using namespace std;
5
6
int pos=0;//the first position of s in t
7
int w=max;//not common count
8
//update by finding
9
10
int len_s,len_t;
11
char s[max],t[max];
12
13
bool find(char *T){
14
int cnt=0;
15
for(int i=0;i<len_s;i++){
16
if(T[i]!=s[i])cnt++;
17
if(cnt >= w) return false;
18
}
19
w = cnt;
20
return true;
21
}
22
23
int main(){
24
scanf("%d%d",&len_s,&len_t);
25
w = len_s;
26
int last = len_t-len_s;
27
28
scanf("%s%s",s,t);
29
for(int i=0;i<=last;i++){
30
if(find(t+i))pos=i;
31
}
32
printf("%d\n",w);
33
for(int i=0;i<len_s;i++){
34
if(t[pos+i]!=s[i]) printf("%d ",i+1);
35
}
36
return 0;
37
}