Skip to content

Commit e8948f5

Browse files
committed
Codechef Beginner Python
0 parents  commit e8948f5

File tree

227 files changed

+3553
-0
lines changed

Some content is hidden

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

227 files changed

+3553
-0
lines changed

A Big Sale.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
for _ in range(int(input())):
2+
n=int(input())
3+
loss=0
4+
for i in range(n):
5+
p,q,d=map(int,input().split())
6+
sp=p+(p*d)/100
7+
sp-=(sp*d)/100
8+
if sp<p:
9+
loss+=(p-sp)*q
10+
print("{:.9f}".format(loss))

A good set.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
for _ in range(int(input())):
2+
n=int(input())
3+
for i in range(n):
4+
print(500-i,end=" ")
5+
print()

ATM cdvta.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
n=int(input())
2+
w=int(input())
3+
h=int(input())
4+
th=int(input())
5+
fh=int(input())
6+
thsnd=int(input())
7+
8+
nthsnd=int(w/1000)
9+
rem=w-1000*nthsnd
10+
11+
nfh=int(rem/500)
12+
rem=rem-nfh*500
13+
14+
nth=int(rem/200)
15+
rem=rem-nth*200
16+
17+
nh=int(rem/100)
18+
19+
if h*100+fh*500+th*200+thsnd*1000<w:
20+
print(0)
21+
else:
22+
if

ATM.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
x,y=input().split()
2+
x=int(x)
3+
y=float(y)
4+
5+
if x%5==0:
6+
if y-x-0.5>=0:
7+
y-=(0.5+x)
8+
y="{0:.2f}".format(y)
9+
print(y)

ATM_Machine.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
for j in range(int(input())):
2+
n, k = [int(x) for x in input().split()]
3+
a = [int(x) for x in input().split()]
4+
5+
for i in range(n):
6+
if a[i] <= k:
7+
k-= a[i]
8+
a[i]= 1
9+
else:
10+
a[i]= 0
11+
for i in range(n):
12+
print(a[i], end="")
13+
print()
14+
15+

ATcdvta.py

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
n=int(input())
2+
w=int(input())
3+
h=int(input())
4+
th=int(input())
5+
fh=int(input())
6+
thsnd=int(input())
7+
8+
fin,ini=0,0
9+
10+
nthsnd = int(w/1000)
11+
nfh = int((w-nthsnd*1000)/500)
12+
nth = int((w-nthsnd*1000-nfh*500)/200)
13+
nh = int((w-nthsnd*1000-nfh*500-nth*200)/100)
14+
'print(nthsnd+nfh+nth+nh,nthsnd,nfh,nth,nh)'
15+
'i=0'
16+
if w>(h*100+th*200+fh*500+thsnd*1000):
17+
print(0)
18+
elif n<(nthsnd+nfh+nth+nh) or h<nh or th<nth or fh<nfh or thsnd<nthsnd:
19+
print(0)
20+
elif n==(nthsnd+nfh+nth+nh) and (nh<=h and nth<=th and nfh<=fh and nthsnd<=thsnd):
21+
print(n)
22+
else:
23+
while True:
24+
'i+=1'
25+
ini = nthsnd+nfh+nth+nh
26+
27+
while 10+nh<=h and nthsnd>0 and (nthsnd-1)+nfh+nth+(nh+10)<=n:
28+
nthsnd=nthsnd-1
29+
nh=nh+10
30+
while 5+nh<=h and nfh>0 and nthsnd+(nfh-1)+nth+(5+nh)<=n:
31+
nfh=nfh-1
32+
nh=nh+5
33+
while 2+nh<=h and nth>0 and nthsnd+nfh+nth-1+nh+2<=n:
34+
nth=nth-1
35+
nh=nh+2
36+
'print("i=" + str(i), nthsnd, nfh, nth, nh)'
37+
38+
while 5+nth<=th and nthsnd>0 and nthsnd-1+nfh+nth+5+nh<=n:
39+
nthsnd=nthsnd-1
40+
nth=nth+5
41+
while 2+nth<=th and 1+nh<=h and nfh>0 and nthsnd+nfh-1+nth+2+nh+1<=n:
42+
nfh=nfh-1
43+
nh=nh+1
44+
nth=nth+2
45+
'print("i=" + str(i), nthsnd, nfh, nth, nh)'
46+
47+
while 2+nfh<=fh and nthsnd>0 and nthsnd-1+nfh+2+nth+nh<=n:
48+
nthsnd=nthsnd-1
49+
nfh=nfh+2
50+
51+
'print("i="+str(i),nthsnd,nfh,nth,nh)'
52+
fin = nthsnd+nfh+nth+nh
53+
if fin==ini:
54+
break
55+
56+
57+
if fin<=n:
58+
print(fin)
59+
else:
60+
print(0)
61+
62+
63+
64+
65+
66+

A_Balanced_contest.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
for _ in range(int(input())):
2+
p2=p10=0
3+
n,p=[int(x) for x in input().split()]
4+
a=[int(x) for x in input().split()]
5+
for i in a:
6+
if i>=(p//2):
7+
p2+=1
8+
elif i<=(p//10):
9+
p10+=1
10+
if p2==1 and p10==2:
11+
print("yes")
12+
else:
13+
print("no")
14+
#what the ****

Ada King.py

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
for _ in range(int(input())):
2+
r,c,k=map(int,input().split())
3+
s=0
4+
5+
one=k
6+
r1=r
7+
r1 -= 1
8+
while one>0 and r1>0:
9+
r1-=1
10+
if ((r1-r)**2)+((c-c)**2) <= 2:
11+
s+=1
12+
else:
13+
break
14+
one-=1
15+
16+
print("s one: "+str(s))
17+
s2=0
18+
19+
two = k
20+
r1 = r
21+
r1 += 1
22+
while two > 0 and r1 < 9:
23+
r1 += 1
24+
if ((r1 - r) ** 2) + ((c - c) ** 2) <= 2:
25+
s += 1
26+
s2+=1
27+
else:
28+
break
29+
two-=1
30+
31+
print("s two: " + str(s2))
32+
s3=0
33+
34+
three = k
35+
c1 = c
36+
c1 -= 1
37+
while three > 0 and c1 > 0:
38+
c1 -= 1
39+
if ((r - r) ** 2) + ((c1 - c) ** 2) <= 2:
40+
s += 1
41+
s3+=1
42+
else:
43+
break
44+
three-=1
45+
46+
print("s three: " + str(s3))
47+
s4=0
48+
49+
four = k
50+
c1 = c
51+
c1 += 1
52+
while four > 0 and c1 < 9:
53+
c1 += 1
54+
if ((r - r) ** 2) + ((c1 - c) ** 2) <= 2:
55+
s += 1
56+
s4+=1
57+
else:
58+
break
59+
four-=1
60+
61+
print("s four: " + str(s4))
62+
s5=0
63+
64+
five = k
65+
r1 = r
66+
c1=c
67+
r1 -= 1
68+
c1 -= 1
69+
while five > 0 and r1 > 0 and c1 >0:
70+
r1 -= 1
71+
c1-=1
72+
if ((r1 - r) ** 2) + ((c1 - c) ** 2) <= 2:
73+
s += 1
74+
s5+=1
75+
else:
76+
break
77+
five-=1
78+
79+
print("s five: " + str(s5))
80+
s6=0
81+
82+
six = k
83+
r1 = r
84+
c1=c
85+
r1 += 1
86+
c1 += 1
87+
while six > 0 and r1 < 9 and c1 < 9:
88+
r1 += 1
89+
c1+=1
90+
if ((r1 - r) ** 2) + ((c1 - c) ** 2) <= 2:
91+
s += 1
92+
s6+=1
93+
else:
94+
break
95+
six-=1
96+
97+
print("s six: " + str(s6))
98+
s7=0
99+
100+
seven = k
101+
r1 = r
102+
c1=c
103+
r1 -= 1
104+
c1 += 1
105+
while seven > 0 and r1 > 0 and c1 < 9:
106+
r1 -= 1
107+
c1+=1
108+
if ((r1 - r) ** 2) + ((c1 - c) ** 2) <= 2:
109+
s += 1
110+
s7+=1
111+
else:
112+
break
113+
seven-=1
114+
115+
print("s seven: " + str(s7))
116+
s8=0
117+
118+
eight = k
119+
r1 = r
120+
c1=c
121+
r1 += 1
122+
c1 -= 1
123+
while eight > 0 and r1 < 9 and c1 > 0:
124+
r1 += 1
125+
c1-=1
126+
if ((r1 - r) ** 2) + ((c1 - c) ** 2) <= 2:
127+
s += 1
128+
s8+=1
129+
else:
130+
break
131+
eight-=1
132+
133+
print("s eight: " + str(s8))
134+
135+
s+=1
136+
print(s)

Ada School.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
for _ in range(int(input())):
2+
n,m=map(int,input().split())
3+
if n==1 or m==1 or (m*n)%2!=0:
4+
print("NO")
5+
else:
6+
print("YES")

Ada and the Staircase.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
for _ in range(int(input())):
2+
n,k=map(int,input().split())
3+
h=[int(x) for x in input().split()]
4+
hf,c=0,0
5+
for i in h:
6+
if i-hf>k:
7+
c+=(i-hf-1)//k
8+
hf=i
9+
print(c)

Akhil_and_coloredBalls.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
for _ in range(int(input())):
2+
X=input().upper()
3+
Y=input().upper()
4+
Z=""
5+
for i in range(len(X)):
6+
if X[i]=='B' and Y[i]=='B':
7+
Z+='W'
8+
else:
9+
Z+='B'
10+
print(Z)

Alternating subarray prefix.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
for _ in range(int(input())):
2+
n=int(input())
3+
a=[0 if int(x)<0 else 1 for x in input().split()]
4+
i,j,k=0,0,0
5+
while i <=(n-1):
6+
s=0
7+
j=i
8+
while j<=(n-1):
9+
if j<n-1:k=j+1
10+
if j==n-1:k=j
11+
if a[j]!=a[k]:
12+
s+=1
13+
j+=1
14+
continue
15+
if a[j]==a[k]:
16+
break
17+
s+=1
18+
for q in range(s,0,-1):
19+
print(q,end=' ')
20+
i=k
21+
if j==n-1:
22+
break
23+
print()

Appy and contest.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import math
2+
for _ in range(int(input())):
3+
n,x,y,k=[int(x) for x in input().split()]
4+
cx=int(n/x)
5+
cy=int(n/y)
6+
clcm=int(n/((x*y)//math.gcd(x,y)))
7+
#print(cx,cy,clcm)
8+
if cx+cy-(2*clcm)>=k:
9+
print("Win")
10+
else:
11+
print("Lose")

Archi and Comparsion.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
for _ in range(int(input())):
2+
a,b,n=map(int,input().split())
3+
if n%2==0:
4+
if abs(a)==abs(b):
5+
print(0)
6+
elif abs(a)>abs(b):
7+
print(1)
8+
else:
9+
print(2)
10+
else:
11+
if a==b:
12+
print(0)
13+
elif a>b:
14+
print(1)
15+
else:
16+
print(2)

Area or perimeter.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'''l=float(input())
2+
b=float(input())
3+
p=2*(l+b)
4+
a=l*b
5+
if a>p:
6+
print("Area")
7+
print(int(a))
8+
elif a<p:
9+
print("Peri")
10+
print(int(p))
11+
else:
12+
print("Eq")
13+
print(int(a))'''
14+
a, b=int(input()), int(input())
15+
a, b=a*b, 2*(a+b)
16+
print("Area"*(a>b)+"Peri"*(b>a)+"Eq"*(b==a),a+(b>a)*(b-a),sep='\n')

0 commit comments

Comments
 (0)