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
1
2
Example
B.Crosswordsolving
......
Lehahastwostringssandt.Thehackerwantstochangethestringsatsuchway,thatitcanbefoundintasasubstring.Allthechangesshouldbethefollowing:Lehachoosesonepositioninthestringsandreplacesthesymbolin
thispositionwiththequestionmark"?".Thehackerissurethatthequestionmarkincomparisoncanplaytheroleofanarbitrarysymbol.Forexample,ifhegetsstrings="ab?b"asaresult,itwillappearint="aabrbb"asasubstring.
Guaranteedthatthelengthofthestringsdoesn'texceedthelengthofthestringt.Helpthehackertoreplaceinsasfewsymbolsaspossiblesothattheresultofthereplacementscanbefoundintasasubstring.Thesymbol"?"
shouldbeconsideredequaltoanyothersymbol.
1
1
2
3
Examples
题目理解:
A:直接do,阶乘可以使用递归
B:暴力比较出最少更改的匹配位置,纪录;暴力完后按纪录的位置重新比较输出。
日期:
2017/7/8
代码:
A
1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
A:找出给出数的娇小数并输出其阶乘。
B:给出两个字符串,比较得出一个字符串成为另一个串的子串需要修改的最少字母数量和位置。
原题目:
A题: http://codeforces.com/problemset/problem/822/A
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
Input2
ThefirstandsinglelinecontainstwointegersAandB(1 ≤ A, B ≤ 109, min(A, B) ≤ 12).
1
Output
2
PrintasingleintegerdenotingthegreatestcommondivisorofintegersA!andB!.
Example
input | output |
43 | 6 |
......
Lehahastwostringssandt.Thehackerwantstochangethestringsatsuchway,thatitcanbefoundintasasubstring.Allthechangesshouldbethefollowing:Lehachoosesonepositioninthestringsandreplacesthesymbolin
thispositionwiththequestionmark"?".Thehackerissurethatthequestionmarkincomparisoncanplaytheroleofanarbitrarysymbol.Forexample,ifhegetsstrings="ab?b"asaresult,itwillappearint="aabrbb"asasubstring.
Guaranteedthatthelengthofthestringsdoesn'texceedthelengthofthestringt.Helpthehackertoreplaceinsasfewsymbolsaspossiblesothattheresultofthereplacementscanbefoundintasasubstring.Thesymbol"?"
shouldbeconsideredequaltoanyothersymbol.
1
Input23
Thefirstlinecontainstwointegersnandm(1 ≤ n ≤ m ≤ 1000)—thelengthofthestringsandthelengthofthestringtcorrespondingly.4
ThesecondlinecontainsnlowercaseEnglishletters—strings.5
ThethirdlinecontainsmlowercaseEnglishletters—stringt.
1
Output
2
Inthefirstlineprintsingleintegerk—theminimalnumberofsymbolsthatneedtobereplaced.
3
Inthesecondlineprintkdistinctintegersdenotingthepositionsofsymbolsinthestringswhichneedtobereplaced.Printthepositionsinanyorder.Ifthereareseveralsolutionsprintanyofthem.Thenumberingofthepositionsbeginsfromone.
Examples
Input | Output |
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;45
intmultip(intn){6
if(n==0)return1;7
returnn*multip(n-1);8
}910
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
}
相关文章推荐
- 0706他人笑我太疯颠
- 0706 第四次作业
- 0706——JAVASE第二天学习
- 0706 第五次作业
- 0706
- 0706
- 0706
- 0706
- 分享下我们部门内部知识点培训教程[SIP/J2ME/Setup/LoadRunner/Domino][0706Up]
- above average(0706)
- 职场笔记[0706]:情绪
- 源码推荐(0706):简单项目分享音乐播放瀑布流等,方便的弹出视图,随意定义
- 分享下我们部门内部知识点培训教程[SIP/J2ME/Setup/LoadRunner/Domino][0706Up]
- 0706
- 职场笔记[0706]:情绪
- 软件测试实习0706-面向对象测试
- 职场笔记[0706]:情绪
- 0706第七讲标准模版库(2)链表
- 职场笔记[0706]:情绪
- AIX: Applying GI patch report ld: 0706-003 Cannot find or read import file: libasmclntsh12.imp (文档 I