2020.12.3--vj個人賽補題
A
Vasyastudiesmusic.Hehaslearnedlotsofinterestingstuff.Forexample,heknowsthatthereare12notes:C,C#,D,D#,E,F,F#,G,G#,A,B,H.Healsoknowsthatthenotesarerepeatedcyclically:afterHgoesCagain,andbeforeCstandsH.WewillconsidertheCnoteintherow'sbeginningandtheCnoteaftertheHsimilarandwewillidentifythemwitheachother.Thedistancebetweenthenotesalongthemusicalscaleismeasuredintones:betweentwoconsecutivenotesthere'sexactlyonesemitone,thatis,0.5tone.Thedistanceistakenfromthelowesttonetotheuppestone,thatis,thedistancebetweenCandEis4semitonesandbetweenEandCis8semitones
Vasyaalsoknowswhatachordis.Achordisanunorderedsetofnolessthanthreenotes.However,fornowVasyaonlyworkswithtriads,thatiswiththechordsthatconsistofexactlythreenotes.Hecanalreadydistinguishbetweentwotypesoftriads—majorandminor.
Let'sdefineamajortriad.LetthetriadconsistofnotesX,YandZ.IfwecanorderthenotessoasthedistancealongthemusicalscalebetweenXandYequals4semitonesandthedistancebetweenYandZis3semitones,thenthetriadismajor.ThedistancebetweenXandZ,accordingly,equals7semitones.
AminortriadisdifferentinthatthedistancebetweenXandYshouldbe3semitonesandbetweenYandZ—4semitones.
Forexample,thetriad"CEG"ismajor:betweenCandEare4semitones,andbetweenEandGare3semitones.Andthetriplet"C#BF"isminor,becauseifweorderthenotesas"BC#F",thanbetweenBandC#willbe3semitones,andbetweenC#andF—4semitones.
HelpVasyaclassifythetriadtheteacherhasgiventohim.
Input
Theonlylinecontains3space-separatednotesintheabove-givennotation.
Output
Print"major"ifthechordismajor,"minor"ifitisminor,and"strange"iftheteachergaveVasyasomeweirdchordwhichisneithermajornorminor.Vasyapromisesyouthattheanswerwillalwaysbeunambiguous.Thatis,therearenochordsthatarebothmajorandminorsimultaneously.
Examples
Input
CEG
Output
major
Input
C#BF
Output
minor
Input
ABH
Output
strange
#include<bits/stdc++.h> using namespace std; int main() { string ch[12]={"C","C#","D","D#","E","F","F#","G","G#","A","B","H"}; string b; int w[5],l=0; for(int i=0;i<3;i++) { cin>>b; for(int j=0;j<12;j++) { if(b==ch[j]) { w[l++]=j; break; } } } sort(w,w+3);///排序後即對應了12個音階從左到右的順序,看做ABC三個,所以只需判斷ABC/CAB/BCA這三種是否滿足3.4或4.3 int str[3]={w[1]-w[0],w[2]-w[1],w[0]+12-w[2] }; if((str[0]==4&&str[1]==3)||(str[1]==4&&str[2]==3)||(str[2]==4&&str[0]==3))cout<<"major"<<endl; else if((str[0]==3&&str[1]==4)||(str[1]==3&&str[2]==4)||(str[2]==3&&str[0]==4))cout<<"minor"<<endl; else cout<<"strange"<<endl; }
B
Vasyalearnstotype.Hehasanunusualkeyboardathisdisposal:itisrectangularandithasnrowsofkeyscontainingmkeysineachrow.Besides,thekeysareoftwotypes.SomeofthekeyshavelowercaseLatinlettersonthemandsomeofthekeysworklikethe"Shift"keyonstandardkeyboards,thatis,theymakelowercaselettersuppercase.
Vasyacanpressoneortwokeyswithonehand.However,hecanonlypresstwokeysiftheEuclideandistancebetweenthecentersofthekeysdoesnotexceedx.Thekeysareconsideredassquareswithasideequalto1.Therearenoemptyspacesbetweenneighbouringkeys.
Vasyaisaverylazyboy,that'swhyhetriestotypewithonehandasheeatschipswithhisotherone.However,itispossiblethatsomesymbolcan'tbetypedwithonehandonly,becausethedistancebetweenitandtheclosest"Shift"keyisstrictlylargerthanx.Inthiscasehewillhavetousehisotherhand.Havingtypedthesymbol,Vasyareturnsotherhandbacktothechips.
YouaregivenVasya'skeyboardandthetext.CounttheminimumnumberoftimesVasyawillhavetousetheotherhand.
Input
Thefirstlinecontainsthreeintegersn,m,x(1 ≤ n, m ≤ 30, 1 ≤ x ≤ 50).
Nextnlinescontaindescriptionsofallthekeyboardkeys.Eachlinecontainsthedescriptionsofexactlymkeys,withoutspaces.Theletterkeysaremarkedwiththecorrespondinglowercaseletters.The"Shift"keysaremarkedwiththe"S"symbol.
Thenfollowthelengthofthetextq(1 ≤ q ≤ 5·105).ThelastlinecontainsthetextT,whichconsistsofqsymbols,whichareuppercaseandlowercaseLatinletters.
Output
IfVasyacantypethetext,thenprinttheminimumnumberoftimeshewillhavetousehisotherhand.Otherwise,print"-1"(withoutthequotes).
Examples
Input
221
ab
cd
1
A
Output
-1
Input
221
ab
cd
1
e
Output
-1
Input
221
ab
cS
5
abcBA
Output
1
Input
394
qwertyuio
asdfghjkl
SzxcvbnmS
35
TheQuIcKbRoWnFOXjummsovertHeLazYDOG
Output
2
Note
Inthefirstsamplethesymbol"A"isimpossibletoprintasthere'sno"Shift"keyonthekeyboard.
Inthesecondsamplethesymbol"e"isimpossibletoprintasthere'snosuchkeyonthekeyboard.
Inthefourthsamplethesymbols"T","G"areimpossibletoprintwithonehand.Theotherlettersthatareonthekeyboardcanbeprinted.Thosesymbolscomeupinthetexttwice,thus,theansweris2.
題解:當文字中的字母在鍵盤中不存在時或者文字中有大寫字母但不存在S鍵時都輸出-1;
其他情況要記錄鍵盤中字母的位置,如果存在S鍵則遍歷計算小寫字母到S的距離是否不超過x,具體看程式碼
#include<bits/stdc++.h> using namespace std; int main() { int n,m,x; cin>>n>>m>>x; char s[100][100];//鍵盤上的字母 char b[500010];//要輸入的文字 int w[100]={0},t[100]={0}; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { cin>>s[i][j]; } } int k=0; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(s[i][j]=='S') { k=1;//用於後面判斷S鍵是否存在 for(int z=0;z<n;z++) { for(int y=0;y<m;y++) { if((z-i)*(z-i)+(y-j)*(y-j)<=x*x)//S鍵周圍可以用一個手摁到的字元 { w[s[z][y]-'a']=1; } } } } else t[s[i][j]-'a']=1;//記錄該字元存在,便於接下來檢查是否存在 } } int q,ct=0,p=0;//ct記錄下用兩隻手的次數 scanf("%d%s",&q,b); for(int l=0;l<q;l++) { if(b[l]>='A'&&b[l]<='Z')//如果要輸入大寫字元 { if(k!=1)//S鍵不存在時,令p=1,直接退出 { p=1; break; } else//存在S鍵時 { if(w[b[l]-'A']!=0){}//要輸入的字母可以用一隻手完成 else if(t[b[l]-'A']==1)ct++;//要輸入的字母要兩隻手完成且存在 else//要輸入的字母不存在時 { p=1; break; } } } else if(t[b[l]-'a']!=1)//輸入小寫字母,且不存在 { p=1; break; } } if(p==1)cout<<"-1"<<endl; else cout<<ct<<endl; }
C
VasyatheprogrammerlivesinthemiddleoftheProgrammingsubwaybranch.Hehastwogirlfriends:DashaandMasha,wholiveatthedifferentendsofthebranch,eachoneisunawareoftheotherone'sexistence.
WhenVasyahassomefreetime,hegoestooneofhisgirlfriends.Hedescendsintothesubwayatsometime,waitsthefirsttraintocomeandridesonittotheendofthebranchtothecorrespondinggirl.However,thetrainsrunwithdifferentfrequencies:atraingoestoDasha'sdirectioneveryaminutes,butatraingoestoMasha'sdirectioneverybminutes.Iftwotrainsapproachatthesametime,Vasyagoestowardthedirectionwiththelowerfrequencyofgoingtrains,thatis,tothegirl,towhosedirectionsthetrainsgolessfrequently(seethenotetothethirdsample).
WeknowthatthetrainsbegintogosimultaneouslybeforeVasyaappears.Thatisthetrainscheduleissuchthatthereexistsamomentoftimewhenthetwotrainsarrivesimultaneously.
HelpVasyacounttowhichgirlfriendhewillgomoreoften.
Input
Thefirstlinecontainstwointegersaandb(a ≠ b, 1 ≤ a, b ≤ 106).
Output
Print"Dasha"ifVasyawillgotoDashamorefrequently,"Masha"ifhewillgotoMashamorefrequently,or"Equal"ifhewillgotobothgirlfriendswiththesamefrequency.
Examples
Input
37
Output
Dasha
Input
53
Output
Masha
Input
23
Output
Equal
Note
Let'stakealookatthethirdsample.Letthetrainsstarttogoatthezeromomentoftime.Itisclearthatthemomentsofthetrains'arrivalwillbeperiodicwithperiod6.That'swhyitisenoughtoshowthatifVasyadescendstothesubwayatamomentoftimeinsidetheinterval(0, 6],hewillgotobothgirlsequallyoften.
Ifhedescendstothesubwayatamomentoftimefrom0to2,heleavesforDashaonthetrainthatarrivesbythesecondminute.
Ifhedescendstothesubwayatamomentoftimefrom2to3,heleavesforMashaonthetrainthatarrivesbythethirdminute.
Ifhedescendstothesubwayatamomentoftimefrom3to4,heleavesforDashaonthetrainthatarrivesbythefourthminute.
Ifhedescendstothesubwayatamomentoftimefrom4to6,hewaitsforbothtrainstoarrivebythesixthminuteandgoestoMashaastrainsgolessofteninMasha'sdirection.
InsumMashaandDashagetequaltime—threeminutesforeachone,thus,Vasyawillgotobothgirlfriendsequallyoften.
題解:我是直接舉的例子找規律做的,先去花費時間少的一方,當時間t%a==0時,Vasya去見Dasha;當t%b==0時,Vasya去見Masha;當t%a==0&&t%b==0時,Vasya去見見面次數比較少的女朋友,當a b 化簡後如果相差1,則結果一樣,若a<b 則為D方,若為a>b則為M
#include<bits/stdc++.h> using namespace std; int gcd (int a,int b) { int t; while(b) { t=a%b; a=b; b=t; } return a; } int main() { int a,b; cin>>a>>b; int t=gcd(a,b); a=a/t; b=b/t; //cout<<a<<" "<<b<<endl; if(abs(a-b)==1)cout<<"Equal"<<endl; else if(a<b)cout<<"Dasha"<<endl; else if(a>b)cout<<"Masha"<<endl; }