1
+ import sys
1
2
import math
2
3
import numpy as np
3
4
@@ -670,6 +671,118 @@ def LemonadeChange():
670
671
671
672
return True
672
673
674
+ # https://leetcode.com/problems/largest-perimeter-triangle/?envType=study-plan-v2&envId=programming-skills
675
+
676
+
673
677
def LargestPerimeterTriangle ():
674
- nums = [2 ,1 ,2 ]
675
-
678
+ nums = [3 , 4 , 15 , 2 , 9 , 4 ]
679
+ nums .sort ()
680
+ for i in range (len (nums ) - 1 , 1 , - 1 ):
681
+ if nums [i - 1 ] + nums [i - 2 ] > nums [i ]:
682
+ return nums [i - 1 ] + nums [i - 2 ] + nums [i ]
683
+ return 0
684
+
685
+
686
+ # https://leetcode.com/problems/check-if-it-is-a-straight-line/?envType=study-plan-v2&envId=programming-skills
687
+ def CheckIfItIsAStraightLine ():
688
+ coordinates = [[0 , 0 ], [0 , 5 ], [5 , 5 ], [5 , 0 ]]
689
+ for i in range (0 , len (coordinates ) - 2 ):
690
+ if (coordinates [i + 1 ][1 ] - coordinates [i ][1 ]) * (coordinates [i + 2 ][0 ] - coordinates [i + 1 ][0 ]) != (coordinates [i + 2 ][1 ] - coordinates [i + 1 ][1 ]) * (coordinates [i + 1 ][0 ] - coordinates [i ][0 ]):
691
+ return False
692
+ return True
693
+
694
+
695
+ # https://leetcode.com/problems/add-binary/description/?envType=study-plan-v2&envId=programming-skills
696
+ def AddBinary ():
697
+ a = "11"
698
+ b = "1"
699
+
700
+ power = 0
701
+ aSum = 0
702
+ bSum = 0
703
+ i = len (a ) - 1
704
+ j = len (b ) - 1
705
+ while i > - 1 or j > - 1 :
706
+ if i > - 1 :
707
+ aSum += pow (2 , power ) if a [i ] == "1" else 0
708
+ if j > - 1 :
709
+ bSum += pow (2 , power ) if b [j ] == "1" else 0
710
+ power += 1
711
+ i -= 1
712
+ j -= 1
713
+
714
+ c = ""
715
+ dividedNumber = aSum + bSum
716
+ if dividedNumber == 0 :
717
+ return "0"
718
+ while dividedNumber >= 1 :
719
+ binary = f"{ dividedNumber % 2 } "
720
+ c = binary + c
721
+ dividedNumber //= 2
722
+
723
+ return c
724
+
725
+
726
+ def isPalindrome (string ):
727
+ i = 0
728
+ j = len (string ) - 1
729
+ while i <= j :
730
+ if string [i ] != string [j ]:
731
+ return False
732
+ i += 1
733
+ j -= 1
734
+ return True
735
+
736
+ # https://dmoj.ca/problem/ccc16j3
737
+
738
+
739
+ def HiddenPalindrome ():
740
+ # str(sys.stdin.readline())
741
+ string = str (sys .stdin .readline ())
742
+ spliceMax = len (string )
743
+
744
+ while spliceMax > 1 :
745
+ i = 0
746
+ while i + spliceMax <= len (string ):
747
+ if isPalindrome (string [i :i + spliceMax ]):
748
+ return len (string [i :i + spliceMax ])
749
+ i += 1
750
+ spliceMax -= 1
751
+ return 1
752
+
753
+ # https://dmoj.ca/problem/ccc10j4
754
+
755
+
756
+ def global_warming ():
757
+ cycles = []
758
+ input_line = sys .stdin .readline ().split (" " )
759
+ while int (input_line [0 ]) != 0 :
760
+ if int (input_line [0 ]) == 1 :
761
+ cycles .append ([int (input_line [1 ])])
762
+ else :
763
+ cycles .append ([int (input_line [i ]) - int (input_line [i - 1 ])
764
+ for i in range (2 , len (input_line ))])
765
+ input_line = sys .stdin .readline ().split (" " )
766
+
767
+ for cycle in cycles :
768
+ min_length = 0
769
+
770
+ for i in range (len (cycle )):
771
+ subset = cycle [0 :i + 1 ]
772
+ is_subset = True
773
+ min_length = len (subset )
774
+ for j in range (i + 1 , len (cycle )):
775
+ if not all (x in subset for x in cycle [j :j + len (subset )]) and not all (x in cycle [j :j + len (subset )] for x in subset ):
776
+ is_subset = False
777
+ break
778
+ if is_subset :
779
+ print (min_length )
780
+ break
781
+ else :
782
+ min_length = 0
783
+ i += 1
784
+ if min_length == 0 :
785
+ print (len (cycle ))
786
+
787
+
788
+ global_warming ()
0 commit comments