0706 CF#822A-I'm bored with life #822B-Crossword solving

摘要
    A:找出给出数的娇小数并输出其阶乘。
    B:给出两个字符串,比较得出一个字符串成为另一个串的子串需要修改的最少字母数量和位置。
原题目
A题 :  http://codeforces.com/problemset/problem/822/A
B题 : http://codeforces.com/problemset/problem/822/B


A. I'm bored with life
......
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 (1A,B109,min(A,B) 12).
1
Output
2
Print a single integer denoting the greatest common divisor of integers A! and B!.
Example
input output
4 3
6

B. Crossword solving
......
Leha has two strings s and t. The hacker wants to change the string s at such way, that it can be found in t as a substring. All the changes should be the following: Leha chooses one position in the string s and replaces the symbol in this position with the question mark "?". The hacker is sure that the question mark in comparison can play the role of an arbitrary symbol. For example, if he gets string s="ab?b" as a result, it will appear in t="aabrbb" as a substring.
 
Guaranteed that the length of the string s doesn't exceed the length of the string t. Help the hacker to replace in s as few symbols as possible so that the result of the replacements can be found in t as a substring. The symbol "?" should be considered equal to any other symbol.

1
Input
2
 
3
The first line contains two integers n and m (1nm1000)  the length of the string s and the length of the string t correspondingly.
4
The second line contains n lowercase English letters  string s.
5
The third line contains m lowercase English letters  string t.

1
Output
2
In the first line print single integer k  the minimal number of symbols that need to be replaced.
3
In the second line print k distinct integers denoting the positions of symbols in the string s which need to be replaced. Print the positions in any order. If there are several solutions print any of them. The numbering of the positions begins from one.
Examples
Input Output
3 5
abc  xaybz
2
2 3
4 10
abc ebceabazcd
1
2

题目理解:
A:直接do,阶乘可以使用递归
B:暴力比较出最少更改的匹配位置,纪录;暴力完后按纪录的位置重新比较输出。

日期
2017/7/8 

代码
A

1
#include <cstdio>
2
#include <algorithm>
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
#include <cstdio>
2
#include <algorithm>
3
#include <cstring>
4
using namespace std;
5
#define max 1005
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
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值