您的位置:首页 > Web前端

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

2017-07-08 00:21 211 查看
摘要

   A:找出给出数的娇小数并输出其阶乘。

   B:给出两个字符串,比较得出一个字符串成为另一个串的子串需要修改的最少字母数量和位置。

原题目

A题: http://codeforces.com/problemset/problem/822/A

B题:http://codeforces.com/problemset/problem/822/B
A.I'mboredwithlife

......

Lehacameupwithataskforhimselftorelaxalittle.HechoosestwointegersAandBandthencalculatesthegreatestcommondivisorofintegers"Afactorial"and"Bfactorial".FormallythehackerwantstofindoutGCD(A!, B!).It'swellknownthatthe
factorialofanintegerxisaproductofallpositiveintegerslessthanorequaltox.Thusx! = 1·2·3·...·(x - 1)·x.Forexample4! = 1·2·3·4 = 24.RecallthatGCD(x, y)isthelargestpositiveintegerqthatdivides(withoutaremainder)bothxandy.

........

1
Input
2
ThefirstandsinglelinecontainstwointegersAandB(1 ≤ A, B ≤ 109, min(A, B) ≤ 12).




1

Output


2

PrintasingleintegerdenotingthegreatestcommondivisorofintegersA!andB!.


Example

inputoutput
43

6


B.Crosswordsolving
......

Lehahastwostringssandt.Thehackerwantstochangethestringsatsuchway,thatitcanbefoundintasasubstring.Allthechangesshouldbethefollowing:Lehachoosesonepositioninthestringsandreplacesthesymbolin
thispositionwiththequestionmark"?".Thehackerissurethatthequestionmarkincomparisoncanplaytheroleofanarbitrarysymbol.Forexample,ifhegetsstrings="ab?b"asaresult,itwillappearint="aabrbb"asasubstring.
 
Guaranteedthatthelengthofthestringsdoesn'texceedthelengthofthestringt.Helpthehackertoreplaceinsasfewsymbolsaspossiblesothattheresultofthereplacementscanbefoundintasasubstring.Thesymbol"?"
shouldbeconsideredequaltoanyothersymbol.

1
Input
2
3
Thefirstlinecontainstwointegersnandm(1 ≤ n ≤ m ≤ 1000)—thelengthofthestringsandthelengthofthestringtcorrespondingly.
4
ThesecondlinecontainsnlowercaseEnglishletters—strings.
5
ThethirdlinecontainsmlowercaseEnglishletters—stringt.




1

Output


2

Inthefirstlineprintsingleintegerk—theminimalnumberofsymbolsthatneedtobereplaced.


3

Inthesecondlineprintkdistinctintegersdenotingthepositionsofsymbolsinthestringswhichneedtobereplaced.Printthepositionsinanyorder.Ifthereareseveralsolutionsprintanyofthem.Thenumberingofthepositionsbeginsfromone.


Examples

InputOutput
35
abc xaybz
2

23
410
abcd ebceabazcd
1

2
题目理解:

A:直接do,阶乘可以使用递归

B:暴力比较出最少更改的匹配位置,纪录;暴力完后按纪录的位置重新比较输出。

日期

2017/7/8 

代码

A



1
#include<cstdio>
2
#include<algorithm>
3
usingnamespacestd;
4
5
intmultip(intn){
6
if(n==0)return1;
7
returnn*multip(n-1);
8
}
9
10
intmain(){
11
inta,b;
12
scanf("%d%d",&a,&b);
13
printf("%d",multip(min(a,b)));
14
return0;
15
}
B





1

#include<cstdio>


2

#include<algorithm>


3

#include<cstring>


4

usingnamespacestd;


5

#definemax1005


6

intpos=0;//thefirstpositionofsint


7

intw=max;//notcommoncount


8

//updatebyfinding


9



10

intlen_s,len_t;


11

chars[max],t[max];


12



13

boolfind(char*T){


14

intcnt=0;


15

for(inti=0;i<len_s;i++){


16

if(T[i]!=s[i])cnt++;


17

if(cnt>=w)returnfalse;


18

}


19

w=cnt;


20

returntrue;


21

}


22



23

intmain(){


24

scanf("%d%d",&len_s,&len_t);


25

w=len_s;


26

intlast=len_t-len_s;


27



28

scanf("%s%s",s,t);


29

for(inti=0;i<=last;i++){


30

if(find(t+i))pos=i;


31

}


32

printf("%d\n",w);


33

for(inti=0;i<len_s;i++){


34

if(t[pos+i]!=s[i])printf("%d",i+1);


35

}


36

return0;


37

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  A+B problem