Skip to content

Commit 8fa2736

Browse files
committed
initial
1 parent daae41b commit 8fa2736

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+321275
-37
lines changed

competitive_programming/__init__.py

Whitespace-only changes.

competitive_programming/contest/__init__.py

Whitespace-only changes.

competitive_programming/contest/test/__init__.py

Whitespace-only changes.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import math
2+
3+
4+
# A class to represent a Point in 2D plane
5+
class Point():
6+
def __init__(self, x, y):
7+
self.x = x
8+
self.y = y
9+
10+
# A utility function to find the
11+
12+
13+
# distance between two points
14+
def dist(p1, p2):
15+
return math.sqrt((p1.x - p2.x) *
16+
(p1.x - p2.x) +
17+
(p1.y - p2.y) *
18+
(p1.y - p2.y))
19+
20+
21+
# A Brute Force method to return the
22+
# smallest distance between two points
23+
# in P[] of size n
24+
def bruteForce(P, n):
25+
min_val = float('inf')
26+
for i in range(n):
27+
for j in range(i + 1, n):
28+
if dist(P[i], P[j]) < min_val:
29+
min_val = dist(P[i], P[j])
30+
31+
return min_val
32+
33+
34+
# A utility function to find the
35+
# distance beween the closest points of
36+
# strip of given size. All points in
37+
# strip[] are sorted accordint to
38+
# y coordinate. They all have an upper
39+
# bound on minimum distance as d.
40+
# Note that this method seems to be
41+
# a O(n^2) method, but it's a O(n)
42+
# method as the inner loop runs at most 6 times
43+
def stripClosest(strip, size, d):
44+
# Initialize the minimum distance as d
45+
min_val = d
46+
47+
strip.sort(key=lambda point: point.y)
48+
49+
# Pick all points one by one and
50+
# try the next points till the difference
51+
# between y coordinates is smaller than d.
52+
# This is a proven fact that this loop
53+
# runs at most 6 times
54+
for i in range(size):
55+
j = i + 1
56+
while j < size and (strip[j].y -
57+
strip[i].y) < min_val:
58+
min_val = dist(strip[i], strip[j])
59+
j += 1
60+
61+
return min_val
62+
63+
64+
# A recursive function to find the
65+
# smallest distance. The array P contains
66+
# all points sorted according to x coordinate
67+
def closestUtil(P, n):
68+
# If there are 2 or 3 points,
69+
# then use brute force
70+
if n <= 3:
71+
return bruteForce(P, n)
72+
73+
# Find the middle point
74+
mid = n // 2
75+
midPoint = P[mid]
76+
77+
# Consider the vertical line passing
78+
# through the middle point calculate
79+
# the smallest distance dl on left
80+
# of middle point and dr on right side
81+
dl = closestUtil(P[:mid], mid)
82+
dr = closestUtil(P[mid:], n - mid)
83+
84+
# Find the smaller of two distances
85+
d = min(dl, dr)
86+
87+
# Build an array strip[] that contains
88+
# points close (closer than d)
89+
# to the line passing through the middle point
90+
strip = []
91+
for i in range(n):
92+
if abs(P[i].x - midPoint.x) < d:
93+
strip.append(P[i])
94+
95+
# Find the closest points in strip.
96+
# Return the minimum of d and closest
97+
# distance is strip[]
98+
return min(d, stripClosest(strip, len(strip), d))
99+
100+
101+
# The main function that finds
102+
# the smallest distance.
103+
# This method mainly uses closestUtil()
104+
def closest(P, n):
105+
P.sort(key=lambda point: point.x)
106+
107+
# Use recursive function closestUtil()
108+
# to find the smallest distance
109+
return closestUtil(P, n)
110+
111+
l=[]
112+
for _ in range(input()):
113+
x, y = map(int, input().split(' '))
114+
l.append(Point(x,y))
115+
116+
n = len(l)
117+
print('{:.8f}'.format(closest(l,n)))
118+
119+
# This code is contributed
120+
# by Prateek Gupta (@prateekgupta10)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
# 5
3+
# 5 3
4+
# 1 5 2 6 1
5+
# 1 6
6+
# 6
7+
# 3 2
8+
# 1 2 3
9+
# 4 3
10+
# 3 1 2 3
11+
# 10 3
12+
# 1 2 3 4 5 6 7 8 9 10
13+
14+
i = int(input())
15+
l = []
16+
for j in range(i):
17+
k = list(map(int,(input().split(' '))))
18+
19+
il = list(map(int,input().split(' ')))
20+
if k[1] in il and len(il)==1:
21+
l.append('yes')
22+
elif k[1] in il[1:] and len(il) % 2 == 1:
23+
l.append('yes')
24+
elif k[1] in il[1:-1] and len(il) % 2 == 0:
25+
l.append('yes')
26+
else:
27+
l.append('no')
28+
29+
for t in l:
30+
print(t)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import math
2+
def c_lcm(greater, l1, l2):
3+
while True:
4+
if greater % l1 == 0 and greater % l2 == 0:
5+
return greater
6+
else:
7+
greater += 1
8+
9+
def gcd(a,b):
10+
if(b==0):
11+
return a
12+
else:
13+
return gcd(b,a%b)
14+
15+
16+
n = input()
17+
l = list(map(int, input().split()))
18+
lcm = []
19+
for i in range(l):
20+
for j in range(i,l):
21+
greater = max(l[i],l[j])
22+
lcm.append(c_lcm(greater, l[i], l[j]))
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import math
2+
3+
n = int(input())
4+
fo = []
5+
for q in range(n):
6+
7+
l = list(map(int, input().split()))
8+
lcm = (l[0] * l[1]) // math.gcd(l[0], l[1])
9+
if l[0] > l[1]:
10+
l[1], l[0] = l[0], l[1]
11+
o = []
12+
for i in range(l[2]):
13+
t = list(map(int, input().split()))
14+
count = 0
15+
16+
if t[1] < l[1]:
17+
o.append(count)
18+
19+
else:
20+
21+
if t[0] < l[1]:
22+
t[0] = l[1]
23+
lower = (t[0] + lcm - 1) // lcm
24+
higher = t[1] // lcm
25+
m = higher - lower + 1
26+
last = ((t[1] // lcm) * lcm) + l[1] - 1
27+
value = t[1] - t[0] + 1 - m * l[1]
28+
# print(m, last, lcm, t[1], t[0], l[1], value)
29+
if last > t[1]:
30+
value = value + last - t[1] +1
31+
32+
o.append(value)
33+
fo.append(o)
34+
35+
for i in fo:
36+
for j in i:
37+
print(j, end=' ')
38+
print()

data_science/sales.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,21 @@ def greater(row):
6565
#%%
6666
sales.loc[sales['STATUS'] == 'Shipped', 'derived'] = 'H'
6767

68+
#%%
69+
import matplotlib.pyplot as plt
70+
import numpy as np
71+
plt.clf()
72+
plt.figure(1) # the first figure
73+
plt.subplot(211) # the first subplot in the first figure
74+
plt.plot([1, 2, 3])
75+
plt.subplot(212) # the second subplot in the first figure
76+
plt.plot([4, 5, 6])
77+
78+
79+
plt.figure(2) # a second figure
80+
plt.plot([4, 5, 6]) # creates a subplot(111) by default
81+
82+
plt.figure(1) # figure 1 current; subplot(212) still current
83+
plt.subplot(211) # make subplot(211) in figure1 current
84+
plt.title('Easy as 1, 2, 3') # subplot 211 title
85+
plt.show()

data_science/second.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,27 @@
33
import numpy as np
44
series = pd.Series([1,2,3,4,5,6,7,8,100], index=['A','B','C','D','E','F','G','H','I'], name='Numbers' )
55

6-
print(series.agg(np.mean))
6+
print(series.agg(np.mean))
7+
8+
9+
#%%
10+
data = pd.DataFrame({'value':[1,2,3,4,5,6,7,8,9,10]})
11+
12+
def compute(row):
13+
if row['value'] > 5:
14+
return 'greater than 5'
15+
elif row['value'] == 5:
16+
return 'equal'
17+
else:
18+
return 'small'
19+
20+
def compute1(data):
21+
if data == 'greater than 5':
22+
return 'Hola than 5'
23+
else:
24+
return data
25+
26+
data['compute'] = data.apply(compute, axis=1)
27+
data.compute= data.compute.transform(compute1)
28+
print(data)
29+

image_processing/1_c.jpg

Loading

image_processing/1_compressed.jpg

5.92 KB
Loading

image_processing/2_c.jpg

141 KB
Loading

image_processing/2_compressed.jpg

5.92 KB
Loading

image_processing/3_c.jpg

32.5 KB
Loading

image_processing/3_compressed.jpg

5.93 KB
Loading

image_processing/4_c.jpg

20.1 KB
Loading

image_processing/4_compressed.jpg

5.93 KB
Loading

image_processing/5_c.jpg

9.53 KB
Loading
Loading
41.9 KB
Loading
41.9 KB
Loading
41.9 KB
Loading
Loading

image_processing/Test_OutGuess_01.jpg

40.8 KB
Loading

image_processing/Test_OutGuess_02.jpg

42 KB
Loading

image_processing/__init__.py

Whitespace-only changes.

image_processing/image_average.jpg

292 KB
Loading

image_processing/image_median.jpg

292 KB
Loading

image_processing/original.jpg

1.08 MB
Loading

image_processing/w_1.jpg

705 KB
Loading

image_processing/w_2.jpg

705 KB
Loading

image_processing/w_3.jpg

705 KB
Loading

image_processing/w_4.jpg

705 KB
Loading

image_processing/w_5.jpg

705 KB
Loading

image_processing/watermark_1.jpg

1.08 MB
Loading

image_processing/watermarking_1.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#%%
2+
import cv2
3+
import matplotlib.pyplot as plt
4+
import numpy as np
5+
6+
#%%
7+
watermark = cv2.imread(r"E:\Pycharm_Workspace\Data_Science\image_processing\watermark_1.jpg")
8+
original_1 = cv2.imread(r'E:\Pycharm_Workspace\Data_Science\image_processing\original.jpg')
9+
10+
diff = watermark != original_1
11+
12+
print(diff.sum())
13+
14+
#%%
15+
16+
mark = 'E:\Pycharm_Workspace\Data_Science\image_processing\w_{}.jpg'
17+
18+
# im1 = mark.format('1')
19+
20+
w_1 = cv2.imread(mark.format('1'))
21+
w_1 = np.array(w_1, dtype=np.uint16)
22+
23+
w_2 = cv2.imread(mark.format('2'))
24+
w_2 = np.array(w_2, dtype=np.uint16)
25+
26+
w_3 = cv2.imread(mark.format('3'))
27+
w_3 = np.array(w_3, dtype=np.uint16)
28+
29+
w_4 = cv2.imread(mark.format('4'))
30+
w_4 = np.array(w_4, dtype=np.uint16)
31+
32+
w_5 = cv2.imread(mark.format('5'))
33+
w_5 = np.array(w_5, dtype=np.uint16)
34+
35+
# average
36+
final_image = (w_1 + w_2 + w_3 + w_4 + w_5)/5
37+
38+
cv2.imwrite('image_processing/image_average.jpg',final_image)
39+
40+
41+
# majority
42+
43+
red = np.array([w_1.T[0],w_2.T[0], w_3.T[0], w_4.T[0], w_5.T[0]])
44+
green = np.array([w_1.T[1],w_2.T[1], w_3.T[1], w_4.T[1], w_5.T[1]])
45+
blue = np.array([w_1.T[2],w_2.T[2], w_3.T[2], w_4.T[2], w_5.T[2]])
46+
47+
red_majority = red.max(axis=0)
48+
green_majority = green.max(axis=0)
49+
blue_majority = blue.max(axis=0)
50+
51+
image_median = np.array([red_majority, green_majority, blue_majority])
52+
cv2.imwrite('image_processing/image_median.jpg',final_image)
53+
54+
55+
#%%
56+
watermark = cv2.imread(r"E:\Pycharm_Workspace\Data_Science\image_processing\StegoWork_with_OutGuess_01.jpg")
57+
original_1 = cv2.imread(r'E:\Pycharm_Workspace\Data_Science\image_processing\original.jpg')
58+
59+
60+
print(original_1.shape)
61+
62+
#%%
63+
64+
watermark = cv2.imread(r"C:\Users\lenovo\Desktop\matlab\input_sat_image.jpg")
65+
cv2.imshow('image',watermark)
66+
67+
#%%
68+
69+
from io import StringIO # "import StringIO" directly in python2
70+
from PIL import Image
71+
# im2 = Image.open('E:\Pycharm_Workspace\Data_Science\image_processing\StegoWork with OutGuess 02.jpg')
72+
# im1 = Image.open('E:\Pycharm_Workspace\Data_Science\image_processing\StegoWork_with_OutGuess_01.jpg')
73+
# im3 = Image.open('E:\Pycharm_Workspace\Data_Science\image_processing\StegoWork_with_OutGuess_03.jpg')
74+
# im4 = Image.open('E:\Pycharm_Workspace\Data_Science\image_processing\StegoWork_with_OutGuess_04.jpg')
75+
76+
im2 = Image.open('E:\Pycharm_Workspace\Data_Science\image_processing\Test_OutGuess_01.jpg')
77+
r, g, b = im2[:,:,0], im2[:,:,1], im2[:,:,2]
78+
im2 = 0.2989 * r + 0.5870 * g + 0.1140 * b
79+
im1 = Image.open('E:\Pycharm_Workspace\Data_Science\image_processing\Test_OutGuess_02.jpg')
80+
81+
im2.save('image_processing/1_c.jpg', quality=0)
82+
im2.save('image_processing/2_c.jpg', quality=100)
83+
im2.save('image_processing/3_c.jpg', quality=50)
84+
im2.save('image_processing/4_c.jpg', quality=30)
85+
im2.save('image_processing/5_c.jpg', quality=10)
86+
# im3.save('image_processing/3_compressed.jpg', quality=0)
87+
# im4.save('image_processing/4_compressed.jpg', quality=0)
88+
89+
#%%
90+
im1 = cv2.imread('E:\Pycharm_Workspace\Data_Science\image_processing\StegoWork with OutGuess 02.jpg',0)
91+
im2 = cv2.imread('E:\Pycharm_Workspace\Data_Science\image_processing\StegoWork_with_OutGuess_01.jpg',0)
92+
im3 = cv2.imread('E:\Pycharm_Workspace\Data_Science\image_processing\StegoWork_with_OutGuess_03.jpg',0)
93+
plt.hist(im1.ravel(),256,[0,256], color='red')
94+
plt.title('IM1')
95+
plt.show()
96+
plt.clf()
97+
plt.hist(im2.ravel(),256,[0,256], color='green')
98+
plt.title('IM2')
99+
plt.show()
100+
plt.clf()
101+
plt.hist(im3.ravel(),256,[0,256], color='blue')
102+
plt.title('IM3')
103+
plt.show()
104+
105+
106+

nextwork_x_module/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)