this is what I made
private static String removeFontSizeFromStyle(String styleContent) { String fontPattern = "[fF][oO][nN][tT][sS][iI][zZ][eE]\\s*:\\s*[09.]+[azAZ%]*\\s*+;?"; return styleContent.replaceAll(fontPattern, ""); }
private static String removeFontSizeFromStyle(String styleContent) { String fontPattern = "[fF][oO][nN][tT][sS][iI][zZ][eE]\\s*:\\s*[09.]+[azAZ%]*\\s*+;?"; return styleContent.replaceAll(fontPattern, ""); }
int c, t, s, i; int luckyandprimeprime(int l, int r) { int[] p = new int[100001]; s = p.length; for ( i = 2; i < s; i++, t=0) while ((t += i) < s) p[t]++; for (i = 0; i < l; i++) if (p[i] == 1) c++; for (i = l; i <= r; i++) { if (p[i] == 1) c++; if (p[c] == 1) t++; } return t; }
P
Prime Prime if the number of prime numbers in the range [1, P]
is prime. Bunny asked Lucky to calculate the number of Prime Prime numbers in the range [l, r]
. Can you you help her?l = 1
and r = 10
, the output should beluckyandprimeprime(l, r) = 4
.4
prime numbers in the given range: 2
, 3
, 5
and 7
. Thus, Prime Prime numbers are 3
, 4
, 5
and 6
, 4
numbers altogether.1 ≤ l ≤ r
.l ≤ r ≤ 10^{5}
.[l, r]
.P
Prime Prime if the number of prime numbers in the range [1, P]
is prime. Bunny asked Lucky to calculate the number of Prime Prime numbers in the range [l, r]
. Can you you help her?l = 1
and r = 10
, the output should beluckyandprimeprime(l, r) = 4
.4
prime numbers in the given range: 2
, 3
, 5
and 7
. Thus, Prime Prime numbers are 3
, 4
, 5
and 6
, 4
numbers altogether.1 ≤ l ≤ r
.l ≤ r ≤ 10^{5}
.[l, r]
.def cuttingRod(s, arr): m = arr[s1] for i in range(1,int(s/2)+1): left= i right =si val = cuttingRod(left, arr) + cuttingRod(right,arr) print(left, right, val) m= max(m, val ) return m def cuttingRodDP(s, arr): m = [0 for i in range(len(arr)+1)] for i in range(1, len(arr)+1): m[i]= arr[i1] maxValue =0 for i in range(1, len(arr)+1): for j in range(1,i+1): maxValue = max(maxValue, m[j] + m[ij]) m[i] = maxValue print(m) return maxValue arr= [ 1 , 5, 8 , 9 , 10, 17, 17, 20] print(cuttingRod(len(arr), arr)) print(cuttingRodDP(len(arr), arr))
# link site is http://www.geeksforgeeks.org/dynamicprogrammingset12longestpalindromicsubsequence/
def lps(str): n = len(str) L = [[0 for col in range(n)] for row in range(n)] for i in range(n): L[i][i] =1 #count for cl in range(2, n+1): for i in range(0, ncl+1): j= i+cl1 if str[i] == str[j] and cl ==2 : L[i][j] =2 elif str[i] == str[j]: L[i][j] = L[i+1][j1] + 2 else : L[i][j] = max(L[i][j1], L[i+1][j]) print(L) return L[0][n1]; print(lps("ABACAA"))
1
x  + 
1
y  = 
1
n 
int c, l; int Bridge(int[] t) { l=t.length; Arrays.sort(t); while(l>3) { c+= Math.min( 2*t[1], t[l  2] + t[0]) + t[l1] + t[0]; l=2; } return c+= l<3?t[l1]:t[1] + t[0]+t[2]; }
int c, i,t; int MaxCupCakes(int N, int[] P, int K) { for (; i < P.length; i++ ) { t= (P[i] c 1); if(K<=t) break; K=Kt; c=P[i]; } return c+K<= N ?c+K : 1; }
int MaxCupCakes(int n, int[] P, int k) { for(int i:P) if(i<=k)k++; return k>n ?1 : k ; }
Max and Caroline, two girls in their midtwenties, work at a Brooklyn restaurant as waitresses. Together, they dream of starting up their cupcake business.One day Max comes with a box ofN
cupcakes numbered according to their quality from1
toN
. Caroline has a list of cupcakesP
that should be removed from the box.Your task it to find the quality of theK^{th}
cupcake after the cupcakes from the listP
are removed from the box.If it is not possible to get theK^{th}
cupcake, return1
instead.ExampleForN = 4
,P = [1]
andK = 2
, the output should beMaxCupCakes(N, P, K) = 3
.Initially there were cupcakes of the following quality:1, 2, 3, 4
. According toP
, the cupcake with quality1
should be removed, so only the following cupcakes are left:2, 3, 4
. The2^{nd}
cupcake in this list is3
, thus the output should be3
as well.
[input] integer NThe number of cupcakes,4 ≤ N ≤ 10^{9}
. [input] array.integer PA sorted array of positive integers, the cupcakes to be removed.0 ≤ P.length ≤ 500
,1 ≤ P[i] ≤ N
. [input] integer KA positive integer, the 1based number of the cupcake to find. [output] integerThe quality of theK^{th}
cupcake, or1
if less thanK
cupcakes are left.
coins = [1, 2, 5, 10, 20, 50, 100, 500, 1000] def find(coins, target): list = []; for i in reversed(range(len(coins))): print(coins[i]) while target>= coins[i]: target = target  coins[i] list.append(coins[i]) return list list = find(coins, 93 ) print(list)
Problem Statement 

You are given two Strings: A and B. Each character in A
is either '0' or '1'. Each character in B is '0', '1', or '?'. A string C matches B if we can change B into C by changing each '?' in B either to '0' or to '1'. Different occurrences of '?' may be changed to different digits. For example, C = "0101" matches B = "01??". Note that each character in C must be either '0' or '1', there cannot be any '?' remaining. Consider all possible strings that match B. How many of these strings occur as a (contiguous) substring in A? Compute and return their number. Note that we only count each good string once, even if it has multiple occurrences in A. 

Definition 



Limits 



Constraints 

  A will contain between 1 and 50 characters, inclusive.  
  B will contain between 1 and 50 characters, inclusive.  
  Each character in A will be '0' or '1'.  
  Each character in B will be '0', '1' or '?'.  
Examples 

0)  


1)  


2)  


3)  


4)  

public long ways(String A, String B){ HashSet<String> set = new HashSet<String>(); int blen = B.length(); for (int i = 0; i <= A.length()blen; i++) { set.add(A.substring(i, i+blen)); } Iterator<String> iter = set.iterator(); int count =0; while (iter.hasNext()) { String str = iter.next(); boolean found = true; for (int i = 0; i < blen; i++) { if(B.charAt(i)!= '?'){ if(A.charAt(i) != B.charAt(i)){ found =false; break; } } } if(found){ count++; } } return count; }
int o = a[0] < a[1] ? 0 :1; for (int i = 1; i < a.length1; i++) if( 0!= (a[i] < a[i+1]?0:1) ) return "not sorted"; return o ==0?"ascending" : "descending";
long a = 0,b= 0,c= 0,d= 0,e= 0,f=1, t = 0; for (int i = 1; i <= n; i++) { t = a+b+c+d+e+f; a=b; b=c; c=d; d=e; e=f; f=t; } return t+"";
Hexanacci numbers: a(n+1) = a(n)+...+a(n5) with a(0)=...=a(4)=0, a(5)=1. 
dic = {} class MinHeapNode: def setNode(self, left, right, freq, char): self.left = left self.right = right self.freq = freq self.char = char return self def huffmanCoding(arr, freq): heapArr = [] for i in range(len(arr)): heapArr.append(MinHeapNode().setNode(None, None , freq[i], arr[i])) print(heapArr[i].freq, heapArr[i].char) while(len(heapArr)>1): left = heapArr.pop(0) right = heapArr.pop(0) insertionSort(heapArr, MinHeapNode().setNode(left, right, left.freq+right.freq, left.char + right.char)) rootheap= heapArr.pop() return rootheap def printHeap(heap, str): if heap.left != None: printHeap(heap.left, str + '0') if heap.right !=None: printHeap(heap.right, str + '1' ) if heap.left == None: print(heap.char, str) dic[heap.char] = str def insertionSort(heapArr, heap): index = len(heapArr) for i in range(len(heapArr)): if heap.freq < heapArr[i].freq: index = i break heapArr.insert(index, heap) def makeNewString(arr, freq): freqcopy = freq[:] arrcopy = arr[:] strval = '' while len(freqcopy) >0: number = random.randrange(0,len(freqcopy)) freqcopy[number] = freqcopy[number]1 strval = strval + arrcopy[number] if freqcopy[number] == 0: freqcopy.pop(number) arrcopy.pop(number) return strval def endcoding(str): strval = '' for i in range(len(str)): strval = strval + dic[str[i]] return strval def huffmandecode(rootheap, strvalencoded): index = 0; orgstr = ''; while index < len(strvalencoded): str = getchar(rootheap, index, strvalencoded) index = index + len(dic[str]) orgstr = orgstr + str return orgstr def getchar(rootheap, index, strvalencoded): if rootheap.left == None: return rootheap.char number = int(strvalencoded[index]) if number ==0: return getchar(rootheap.left, index+1, strvalencoded) if number ==1: return getchar(rootheap.right, index+1, strvalencoded) arr = ['a', 'b', 'c', 'd', 'e', 'f'] freq = [5, 9, 12, 13, 16, 45] rootheap = huffmanCoding(arr, freq) printHeap(rootheap, '') strval = makeNewString(arr, freq) print("org ", strval) strvalencoded = endcoding(strval) print("encoded ",strvalencoded) orgencoded = huffmandecode(rootheap, strvalencoded) print("decoded ", orgencoded)
# make setdef MakeSet(number): return node().set(number) # find rootdef find(x): if x.parent.number == x.number: return x else: return find(x.parent) # merge two setsdef union(x, y): xRoot = find(x) yRoot = find(y) xRoot.parent = yRoot class node(): def set(self, number): self.parent = self self.number = number return self # make setsets = list(map(lambda x:MakeSet(x), range(10))) for i in range(len(sets)): print(sets[i].number, sets[i].parent) # one set is 04 super root is 4for i in range(0, 4): union(sets[i], sets[i+1]) # the otehr set is 5~9 super root is 9for i in range(5, len(sets)1): union(sets[i], sets[i+1]) # test for all nodes finding root nodefor i in range(len(sets)): print(i ," parent > ", find(sets[i]).number)
package numberFrom400; import java.util.Arrays; import euler.util.EulerUtil; public class number491 { public static long totalCase = 0; public static int total = 0; public static int sum = 90; public static void main(String args[]){ long start = System.currentTimeMillis(); int numbers[] = new int[10]; searching(0, 0, numbers); System.out.println(totalCase); System.out.println(System.currentTimeMillis()start); } public static void searching(int position, int count, int[]arr ){ if(position>=arr.length){ if(count == 10){ // 여기서 시작한다. 왼쪽 섬 int subsum = 0; for (int i = 0; i < arr.length; i++) { if(arr[i] != 0){ int val = i *arr[i]; subsum += val; } } if((subsum (sum  subsum))%11 ==0){ // System.out.println("this num is divisible"); // System.out.println(Arrays.toString(arr)); // System.out.println(Arrays.toString(reversse(arr)) + " re "); // 여기가 Divisible이 가능한 위치 int twocount = 0; for (int i = 0; i < arr.length; i++) { if(arr[i]== 2){ twocount ++; } } long leftCase = EulerUtil.getFactorial(10)/(long)Math.pow(2, twocount); if(arr[0] ==1 ){ leftCase = (leftCase  EulerUtil.getFactorial(9)/(long)Math.pow(2, twocount)); }else if (arr[0] ==2) { leftCase = (leftCase  EulerUtil.getFactorial(9)/(long)Math.pow(2, twocount1)); } int[] reverse = reversse(arr); // right case twocount = 0; for (int i = 0; i < reverse.length; i++) { if(reverse[i]== 2){ twocount ++; } } long rightCase = EulerUtil.getFactorial(10)/(long)Math.pow(2, twocount); totalCase = totalCase + (leftCase * rightCase ); }else{ } total++; return; }else if(count > 5){ return; } return; } for (int i = 0; i < 3; i++) { arr[position] = i; searching(position+1, count+i, arr); arr[position] = 0; } } public static int[] reversse (int arr[]){ int reverse[]= new int[arr.length]; for (int i = 0; i < arr.length; i++) { reverse[i] = 2  arr[i]; } return reverse; } }