Python代写-PURMHFW 2 Q1
时间:2021-03-31
31/03/2021 CRS\ RI PURMHFW 2 Q1 - CROabRUaWRU\
KWWSV://FROab.UHVHaUFK.JRRJOH.FRP/GULYH/1T4]I[6BGMFIJR1IU-T8ZLWX2U[V9RTA3#SULQWMRGH=WUXH 1/7
GO 8O P2 HSQI ` Q1 ` Q2 ` Q3
BIJSVI ]SY WXEVX, VYR XLI RI\X GSHI JVEKQIRX XS HS[RPSEH CS: (GSQQE WITEVEXIH ZEPYIW) ¦PIW XLEX
]SY [MPP RIIH XS ]SYV GSPEF IRZMVSRQIRX ¦VWX:
Q1
fURm¦XUllib.UeTXeVW¦imSRUW¦XUlUeWUieYe
imSRUW¦RV
¦
def¦dRZnlRad(XUl,¦file):
¦¦if¦RV.SaWh.iVfile(file):
¦¦¦¦SUinW(file¦+¦"¦alUead\¦dRZnlRaded.¦YRX¦can¦Vee¦iW¦if¦\RX¦click¦Rn¦Whe¦fRldeU¦icRn¦
¦¦elVe:
¦¦¦¦SUinW("DRZnlRading¦file¦"¦+¦file¦+¦"¦...",¦end="")
¦¦¦¦XUlUeWUieYe(XUl,file)
¦¦¦¦SUinW("OK")
¦
dRZnlRad('hWWS://Ued.VmX.edX.Vg/UeVRXUceV/GUaShLab.S\','GUaShLab.S\')¦¦#¦GUaShLab)
dRZnlRad('hWWS://Ued.VmX.edX.Vg/UeVRXUceV/caVe1.cVY','caVe1.cVY')¦¦#¦caVe1.cVY
dRZnlRad('hWWS://Ued.VmX.edX.Vg/UeVRXUceV/caVe1a.cVY','caVe1a.cVY')¦#¦caVe1a.cVY
dRZnlRad('hWWS://Ued.VmX.edX.Vg/UeVRXUceV/caVe1b.cVY','caVe1b.cVY')¦#¦caVe1b.cVY
dRZnlRad('hWWS://Ued.VmX.edX.Vg/UeVRXUceV/caVe2.cVY','caVe2.cVY')¦¦#¦caVe2.cVY
dRZnlRad('hWWS://Ued.VmX.edX.Vg/UeVRXUceV/caVe3.cVY','caVe3.cVY')¦¦#¦caVe3.cVY
dRZnlRad('hWWS://Ued.VmX.edX.Vg/UeVRXUceV/caVe4.cVY','caVe4.cVY')¦¦#¦caVe4.cVY
dRZnlRad('hWWS://Ued.VmX.edX.Vg/UeVRXUceV/caVe5.cVY','caVe5.cVY')¦¦#¦caVe5.cVY
A G]GPI MR E KVETL MW E TEXL MR [LMGL XLI SRP] VITIEXIH ZIVXMGIW EVI XLI ¦VWX ERH PEWX ZIVXMGIW. A
HMVIGXIH G]GPI MR E HMVIGXIH KVETL MW E TEXL MR [LMGL XLI SRP] VITIEXIH ZIVXMGIW EVI XLI ¦VWX ERH PEWX
ZIVXMGIW.
FMKYVI 1 FIPS[ MW FEWIH SR case1.csY . 8LIVI EVI E JI[ G]GPIW MR XLMW KVETL:
0 --> 1 --> 2 --> 0
1 --> 4 --> 3 --> 1
1 --> 2 --> 3 --> 1
31/03/2021 CRS\ RI PURMHFW 2 Q1 - CROabRUaWRU\
KWWSV://FROab.UHVHaUFK.JRRJOH.FRP/GULYH/1T4]I[6BGMFIJR1IU-T8ZLWX2U[V9RTA3#SULQWMRGH=WUXH 2/7
FMKYVI 1. A KVETL WLS[MRK E WMQTPI 8[IIXIV RIX[SVO [MXL 11 YWIVW ( case1.csY )
8LI GLEPPIRKI RS[ MW XS ¦RH E G]GPI WXEVXMRK JVSQ ER] KMZIR RSHI S , WYGL XLEX XLI G]GPI MW EW FMK EW
TSWWMFPI (FMK MR XIVQW SJ XLI RYQFIV SJ RSHIW MR XLI G]GPI).
score = nXmber of nodes in c\cle retXrned b\ \oXr algorithm
=SY [ERX XLI WGSVI XS FI EW LMKL EW TSWWMFPI. FSV XLI GEWI SJ ¦KYVI 1, EPP 3 TSWWMFPI G]GPIW LEZI XLI
WEQI WGSVI SJ 3 . IX MW TSWWMFPI XLEX XLIVI MW RS G]GPI XLEX GER FI JSVQIH JVSQ S EW [IPP.
HIVI MW E 2RH I\EQTPI GEPPIH case1a.csY [MXL 11 RSHIW:
UWeV ID DiVecX FSPPS[eV UWeV IDW
0 5, 8, 10
1 2, 6
2 1, 3
3 1, 5
4 2, 5
5 4, 6, 9
6 1, 3, 9
7 6
8 7, 10
9 0, 6, 8, 10
10 -
8LMW MW LS[ case1a.csY [MPP FI VITVIWIRXIH EW E PMWX:
HIVI MW LS[ case1a.csY PSSOW PMOI ZMWYEPP]:
fROORZeUV_1a¦=¦[[5,¦8,¦10],¦[2,¦6],¦[1,¦3],¦[1,¦5],¦[2,¦5],¦[4,¦6,¦9],¦[1,¦3,¦9],¦[6],¦[7,¦10
31/03/2021 CRS\ RI PURMHFW 2 Q1 - CROabRUaWRU\
KWWSV://FROab.UHVHaUFK.JRRJOH.FRP/GULYH/1T4]I[6BGMFIJR1IU-T8ZLWX2U[V9RTA3#SULQWMRGH=WUXH 3/7
FMKYVI 2. A KVETL WLS[MRK E WMQTPI 8[IIXIV RIX[SVO [MXL 11 YWIVW ( case1a.csY )
;VMXI E JYRGXMSR GEPPIH get_c\cle(folloZers, s) XLEX XEOIW MR E 2D PMWX XLEX VITVIWIRXW E RIX[SVO
SJ 8[IIXIV YWIVW. s MW ER MRXIKIV XLEX VITVIWIRXW SRI SJ XLI 8[IIXIV YWIVW. =SYV JYRGXMSR VIXYVRW
IMXLIV:
[] , MJ XLIVI MW RS G]GPI WXEVXMRK JVSQ, ERH IRHMRK EX s .
E 1D PMWX SJ YWIV IDW VITVIWIRXMRK E G]GPI WXEVXMRK JVSQ, ERH IRHMRK EX s (MRGPYHMRK s ).
IJ XLIVI MW EX PIEWX 1 G]GPI JVSQ s , ]SYV WGSVI WLEPP FI XLI RYQFIV SJ YWIVW MR ]SYV VIXYVRIH G]GPI.
8LI PEVKIV ]SYV G]GPI (ERH WGSVI), XLI FIXXIV. 8LI qXalit\ WGSVI XLEX ]SY WII EX red MW XLMW WGSVI.
=SY GER EWWYQI XLEX XLI 8[IIXIV YWIVW EP[E]W LEZI GSRWIGYXMZI MRXIKIV IDW WXEVXMRK JVSQ 0 , ERH
XLEX s MW EP[E]W E ZEPMH YWIV ID.
e.g.¦1:¦(caVe1a.cVY)
fROORZeUV_1a¦=¦[[5,¦8,¦10],¦[2,¦6],¦[1,¦3],¦[1,¦5],¦[2,¦5],¦[4,¦6,¦9],¦[1,¦3,¦9],¦[6],¦[7,¦10
geW_c\cOe(fROORZeUV_1a,¦2)¦Pa\¦UeWXUQ¦aQ\¦Rf¦Whe¦fROORZiQg¦(VcRUeV¦iQdicaWed):
¦¦[]¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦#¦VcRUe¦=¦0
¦¦[2,¦4,¦5,¦3,¦2]¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦#¦VcRUe¦=¦4
¦¦[2,¦4,¦5,¦0,¦9,¦6,¦1,¦2]¦¦¦¦¦¦¦#¦VcRUe¦=¦7
¦¦[2,¦1,¦2]¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦#¦VcRUe¦=¦2
¦¦[2,¦1,¦3,¦2]¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦#¦VcRUe¦=¦3
¦¦[2,¦1,¦6,¦5,¦3,¦2]¦¦¦¦¦¦¦¦¦¦¦¦¦#¦VcRUe¦=¦5
¦¦[2,¦1,¦6,¦9,¦5,¦3,¦2]¦¦¦¦¦¦¦¦¦¦#¦VcRUe¦=¦6
¦¦[2,¦1,¦6,¦7,¦8,¦9,¦5,¦3,¦2]¦¦¦¦#¦VcRUe¦=¦8
¦¦[2,¦1,¦6,¦7,¦8,¦0,¦9,¦5,¦3,¦2]¦#¦VcRUe¦=¦9
=SYV 8EWO
31/03/2021 CRS\ RI PURMHFW 2 Q1 - CROabRUaWRU\
KWWSV://FROab.UHVHaUFK.JRRJOH.FRP/GULYH/1T4]I[6BGMFIJR1IU-T8ZLWX2U[V9RTA3#SULQWMRGH=WUXH 4/7
FMPP YT XLMW JYRGXMSR:
e.g.¦2:¦(caVe1a.cVY)
fROORZeUV_1a¦=¦[[5,¦8,¦10],¦[2,¦6],¦[1,¦3],¦[1,¦5],¦[2,¦5],¦[4,¦6,¦9],¦[1,¦3,¦9],¦[6],¦[7,¦10
geW_c\cOe(fROORZeUV_1a,¦10)¦VhRXOd¦UeWXUQ¦[]
The¦VcRUe¦iV¦0,¦bXW¦WhaW'V¦Whe¦cRUUecW¦YaOXe¦WR¦be¦UeWXUQed¦ViQce¦WheUe¦iV¦QR¦c\cOe¦WhaW¦VWaU
#¦EXTRACT¦THIS¦CODE¦&¦SUBMIT¦AS¦S2T1.S\¦TO¦RED!!!
#¦Filename:¦S2T1.S\
#¦Team¦ID:¦
¦
#¦E[ceSW¦imSRUW¦VWaWemenWV,¦all¦RWheU¦VWaWemenWV¦VhRXld¦Rnl\¦be¦in¦fXncWiRnV.
#¦imSRUW¦GUaShLab¦¦#¦<--¦XncRmmenW¦if¦\RX¦ZanW¦WR¦XVe¦GUaShLab
¦
def¦geW_c\cle(fRllRZeUV,¦V):
¦¦#¦TODO:¦ediW¦WhiV¦fXncWiRn.
¦¦UeWXUn¦[]¦¦
RYR XLI JSPPS[MRK GSHI ¦VWX. 8LIWI JYRGXMSRW [MPP FI GEPPIH F] XLI XIWX GEWIW FIPS[.
8IWX CEWIW
imSRUW¦cRS\,¦Wime
#¦---------------------------------------------------------------------------
#¦UeadV¦a¦CSV¦file¦and¦UeWXUnV¦a¦2D¦liVW¦Rf¦inWV
#¦e.g.¦Uead_file("caVe1.cVY")¦Zill¦UeWXUn:¦[[2],¦[0,¦3],¦[0,¦1],¦[1,¦2,¦4,¦5],¦[1,¦6,¦
def¦Uead_file(file_name):
¦¦inSXW¦=¦[]
¦¦ZiWh¦RSen(file_name,¦"U")¦aV¦file:
¦¦¦¦fRU¦line¦in¦file:
¦¦¦¦¦¦line¦=¦line.UVWUiS("\n")
¦¦¦¦¦¦cXUUenW_liVW¦=¦line.VSliW(",")
¦¦¦¦¦¦inde[¦=¦inW(cXUUenW_liVW.SRS(0))¦¦#¦1VW¦elemenW¦iV¦Whe¦inde[.¦aVVXmSWiRn:¦Whe¦in
¦¦¦¦¦¦cXUUenW_liVW¦=¦[inW(i)¦fRU¦i¦in¦cXUUenW_liVW]¦¦#¦cRnYeUW¦all¦elemenWV¦fURm¦VWUin
¦¦¦¦¦¦inSXW.aSSend(cXUUenW_liVW)¦¦¦¦¦¦¦¦#¦inVeUW¦inWR¦liVW¦¦¦
¦¦UeWXUn¦inSXW
#¦---------------------------------------------------------------------------
#¦WakeV¦in¦an¦anVZeU¦(e.g.¦[1,2,7,1]),¦V,¦laUgeVW_id.¦And¦UeWXUnV¦eiWheU
#¦-¦an¦eUURU¦meVVage¦(VWUing),¦RU
#¦-¦NRne¦(meaning¦WheUe¦iV¦nR¦eUURU¦ZiWh¦V\nWa[¦Rf¦anVZeU).¦¦
#¦NRWe:¦E[ceSW¦WhaW¦\RXU¦1VW¦and¦laVW¦elemenW¦VhRXld¦be¦Whe¦Vame,¦anVZeU¦VhRXld¦nRW¦cR
def¦geW_V\nWa[_eUU_mVg_T1(anVZeU,¦V,¦laUgeVW_id):
¦¦if¦anVZeU¦==¦NRne:
¦¦¦¦UeWXUn¦"EUURU:¦\RXU¦fXncWiRn¦UeWXUned¦NRne.¦IW¦VhRXld¦UeWXUn¦a¦liVW¦Rf¦inWegeUV."
¦¦elif¦anVZeU¦==¦[]:
¦¦¦¦UeWXUn¦NRne
31/03/2021 CRS\ RI PURMHFW 2 Q1 - CROabRUaWRU\
KWWSV://FROab.UHVHaUFK.JRRJOH.FRP/GULYH/1T4]I[6BGMFIJR1IU-T8ZLWX2U[V9RTA3#SULQWMRGH=WUXH 5/7
¦¦elif¦W\Se(anVZeU)¦iV¦nRW¦liVW:
¦¦¦¦UeWXUn¦"EUURU:¦\RXU¦fXncWiRn¦UeWXUned¦VRmeWhing¦RWheU¦Whan¦a¦liVW.¦IW¦VhRXld¦UeWXU
¦¦elif¦nRW¦all(iVinVWance(i,¦inW)¦fRU¦i¦in¦anVZeU):¦¦#¦check¦if¦all¦elemenWV¦in¦anVZeU
¦¦¦¦UeWXUn¦"EUURU:¦\RXU¦fXncWiRn¦UeWXUned¦a¦liVW¦Rf¦elemenWV,¦bXW¦nRW¦all¦Rf¦Whem¦aUe¦
¦¦elif¦len(anVZeU)<3:¦
¦¦¦¦UeWXUn¦"EUURU:¦\RXU¦anVZeU¦VhRXld¦cRnWain¦aW¦leaVW¦3¦inWegeUV¦fRU¦iW¦WR¦UeSUeVenW¦
¦¦elif¦anVZeU[0]¦!=¦V:
¦¦¦¦UeWXUn¦"EUURU:¦Whe¦fiUVW¦elemenW¦in¦\RXU¦anVZeU¦VhRXld¦be¦"¦+¦VWU(V)
¦¦elif¦anVZeU[-1]¦!=¦V:
¦¦¦¦UeWXUn¦"EUURU:¦Whe¦laVW¦elemenW¦in¦\RXU¦anVZeU¦VhRXld¦be¦"¦+¦VWU(V)¦¦¦
¦¦elif¦len(anVZeU)-1¦!=¦len(VeW(anVZeU[:-1])):¦¦#¦Zill¦be¦TUXe¦if¦anVZeU¦cRnWainV¦UeSe
¦¦¦¦UeWXUn¦"EUURU:¦WheUe¦aUe¦UeSeaWed¦elemenWV¦in¦\RXU¦anVZeU.¦Onl\¦Whe¦1VW¦and¦laVW¦e
¦¦elif¦nRW¦all(i<=laUgeVW_id¦and¦i>=0¦fRU¦i¦in¦anVZeU):
¦¦¦¦UeWXUn¦"EUURU:¦WheUe¦aUe¦elemenWV¦in¦\RXU¦anVZeU¦WhaW¦aUe¦negaWiYe¦RU¦e[ceed¦Whe¦l
¦¦elVe:
¦¦¦¦UeWXUn¦NRne¦¦#¦nR¦V\nWa[¦SURblem,¦nR¦eUURU¦mVg
#¦---------------------------------------------------------------------------
#¦check¦if¦anVZeU¦iV¦a¦c\cle,¦and¦calcXlaWe¦VcRUe.¦UeWXUnV¦eiWheU¦NRne¦(nRW¦a¦c\cle),¦
def¦geW_VcRUe_T1(anVZeU,¦fRllRZeUV):
¦¦if¦anVZeU¦==¦[]:
¦¦¦¦UeWXUn¦0¦#¦VcRUe¦iV¦]eUR
¦
¦¦#¦check¦WhaW¦Whe¦elemenWV¦in¦anVZeU¦fRUm¦a¦SaWh
¦¦fRU¦i¦in¦Uange(1,¦len(anVZeU)):
¦¦¦¦cXUUenW_id¦=¦anVZeU[i]
¦¦¦¦SUeY_id¦=¦anVZeU[i-1]
¦
¦¦¦¦if¦nRW¦SUeY_id¦in¦fRllRZeUV[cXUUenW_id]:
¦¦¦¦¦¦SUinW("EUURU:¦ThiV¦iV¦nRW¦a¦c\cle.¦UVeU¦"¦+¦VWU(SUeY_id)¦+¦"¦iV¦nRW¦fRllRZing¦XV
¦¦¦¦¦¦UeWXUn¦NRne¦#¦eUURU
¦
¦¦UeWXUn¦len(anVZeU)¦-¦1¦#¦VcRUe
#¦---------------------------------------------------------------------------
#¦WeVW¦caVe
def¦UXn_WeVW_caVe_T1(WeVW_caVe_name,¦file_name,¦V):
¦¦SUinW("TeVW¦CaVe¦:"¦+¦WeVW_caVe_name¦+¦",¦file_name¦:"¦+¦file_name¦+¦",¦V¦=¦"¦+¦VWU(
¦
¦¦fRllRZeUV¦=¦Uead_file(file_name)
¦¦fRllRZeUV_clRne¦=¦cRS\.deeScRS\(fRllRZeUV)¦#¦make¦a¦clRne.¦WhiV¦clRne¦Zill¦be¦SaVVed
¦¦VWaUW_Wime¦=¦Wime.Wime()
¦¦anVZeU¦=¦geW_c\cle(fRllRZeUV_clRne,¦V)¦¦#¦callV¦\RXU¦fXncWiRn
¦¦Wime_Waken¦=¦Wime.Wime()¦-¦VWaUW_Wime
¦¦SUinW("E[ecXWiRn¦Wime¦"¦+¦VWU(Wime_Waken)¦+¦"¦VecRndV.\n")¦¦¦¦#¦diVSla\¦Wime¦laSVed
¦
¦¦#¦SUinW¦RXWcRme
¦¦SUinW("YRXU¦fXncWiRn¦UeWXUned:¦"¦+¦VWU(anVZeU))
¦
¦¦#¦check¦V\nWa[¦cRUUecWneVV
¦¦laUgeVW_id¦=¦len(fRllRZeUV)-1
¦¦eUU_mVg¦=¦geW_V\nWa[_eUU_mVg_T1(anVZeU,¦V,¦laUgeVW_id)
¦¦if¦eUU_mVg¦!=¦NRne:
SUinW(eUU mVg)
31/03/2021 CRS\ RI PURMHFW 2 Q1 - CROabRUaWRU\
KWWSV://FROab.UHVHaUFK.JRRJOH.FRP/GULYH/1T4]I[6BGMFIJR1IU-T8ZLWX2U[V9RTA3#SULQWMRGH=WUXH 6/7
¦¦¦¦SUinW(eUU_mVg)
¦¦¦¦SUinW("TeVW¦caVe¦"¦+¦WeVW_caVe_name¦+¦"¦*****¦FAILED¦*****")
¦¦¦¦UeWXUn¦NRne
¦¦
¦¦#¦geW¦VcRUe
¦¦VcRUe¦=¦geW_VcRUe_T1(anVZeU,¦fRllRZeUV)
¦¦if¦VcRUe¦==¦NRne:
¦¦¦¦SUinW("TeVW¦caVe¦"¦+¦WeVW_caVe_name¦+¦"¦*****¦FAILED¦*****")
¦¦elVe:
¦¦¦¦SUinW("TeVW¦caVe¦"¦+¦WeVW_caVe_name¦+¦"¦SaVVed")
¦¦¦¦SUinW("ScRUe¦:¦"¦+¦VWU(VcRUe))
8LIWI EVI XIWX GEWIW XS GLIGO ]SYV get_c\cle JYRGXMSR. =SY EVI IRGSYVEKIH XS GVIEXI ]SYV S[R
XIWX GEWIW XS XIWX ]SYV JYRGXMSR YWMRK XLI SXLIV CS: ¦PIW. RIQIQFIV XLEX ]SYV EPKSVMXLQ MW I\TIGXIH
XS [SVO [MXL EPP TSWWMFPI 8[IIXIV RIX[SVOW.
#¦WeVW¦caVe¦T1_1a_2¦-¦Q1,¦caVe1a.cVY,¦V=2
file_name¦=¦"caVe1a.cVY"
V¦=¦2
UXn_WeVW_caVe_T1("T1_1a_2",¦file_name,¦V)
#¦WeVW¦caVe¦T1_1a_3¦-¦Q1,¦caVe1a.cVY,¦V=3
file_name¦=¦"caVe1a.cVY"
V¦=¦3
UXn_WeVW_caVe_T1("T1_1a_3",¦file_name,¦V)
#¦WeVW¦caVe¦T1_1a_10¦-¦Q1,¦caVe1a.cVY,¦V=10
file_name¦=¦"caVe1a.cVY"
V¦=¦10
UXn_WeVW_caVe_T1("T1_1a_10",¦file_name,¦V)
#¦WeVW¦caVe¦T1_1a_6¦-¦Q1,¦caVe1a.cVY,¦V=6
file_name¦=¦"caVe1a.cVY"
V¦=¦6
UXn_WeVW_caVe_T1("T1_1a_6",¦file_name,¦V)
#¦WeVW¦caVe¦T1_2_10¦-¦Q1,¦caVe2.cVY,¦V=10
file_name¦=¦"caVe2.cVY"
V¦=¦10
UXn_WeVW_caVe_T1("T1_2_10",¦file_name,¦V)
p2q1.p\ XS VIH
VITSVX (XSXEP SJ QE\ 3 WPMHIW JSV EPP UYIWXMSRW; RSX 3 WPMHIW TIV UYIWXMSR) XS IPIEVR
8S SYFQMX:
31/03/2021 CRS\ RI PURMHFW 2 Q1 - CROabRUaWRU\
KWWSV://FROab.UHVHaUFK.JRRJOH.FRP/GULYH/1T4]I[6BGMFIJR1IU-T8ZLWX2U[V9RTA3#SULQWMRGH=WUXH 7/7
1 QEVO JSV GSVVIGXRIWW.
1 QEVO JSV WTIIH.
1 QEVO JSV UYEPMX].
OXLIV XIWX GEWIW [MPP FI YWIH SR red . =SY QYWX IRWYVI XLEX ]SYV JYRGXMSR HSIW RSX XMQI-SYX SR
red . A GSVVIGX ERW[IV XLEX HSIW RSX XMQI SYX SR red [MPP KIX EX PIEWX 1 QEVO. =SY [MPP SRP] KIX
QEVOW JSV WTIIH ERH UYEPMX] MJ ]SYV WSPYXMSR MW GSVVIGX.
AWWIWWQIRX:
GO 8O P2 HSQI ` Q1 ` Q2 ` Q3


essay、essay代写