Skip to content

Commit 29da59d

Browse files
Codechef July 2020
1 parent 7fef9a3 commit 29da59d

File tree

2 files changed

+88
-58
lines changed

2 files changed

+88
-58
lines changed

Codechef/July 2020/JULY_2020.ipynb

Lines changed: 78 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -336,106 +336,126 @@
336336
},
337337
{
338338
"cell_type": "code",
339-
"execution_count": 3,
339+
"execution_count": 1,
340340
"metadata": {},
341341
"outputs": [
342342
{
343-
"data": {
344-
"text/plain": [
345-
"[[1, 1], [1, 2], [4, 6], [2, 1], [9, 6], [9, 3], [4, 3]]"
346-
]
347-
},
348-
"execution_count": 3,
349-
"metadata": {},
350-
"output_type": "execute_result"
351-
}
352-
],
353-
"source": [
354-
"l"
355-
]
356-
},
357-
{
358-
"cell_type": "code",
359-
"execution_count": 8,
360-
"metadata": {},
361-
"outputs": [
343+
"name": "stdin",
344+
"output_type": "stream",
345+
"text": [
346+
" 1\n",
347+
" 2\n",
348+
" 1 1\n",
349+
" 1 2\n",
350+
" 4 6\n",
351+
" 2 1\n",
352+
" 9 6\n",
353+
" 9 3\n",
354+
" 4 3\n"
355+
]
356+
},
362357
{
363358
"name": "stdout",
364359
"output_type": "stream",
365360
"text": [
366-
"2 2\n"
361+
"2 2 \n"
367362
]
368363
}
369364
],
370365
"source": [
371-
"for i,j in zip(l1,l2):\n",
372-
" if l1.count(i)%2==1:\n",
373-
" x=i\n",
374-
" if l2.count(j)%2==1:\n",
375-
" y=j\n",
376-
"print(x,y)"
366+
"from functools import reduce\n",
367+
"for _ in range(int(input())):\n",
368+
" n=int(input())\n",
369+
" l1=[]\n",
370+
" l2=[]\n",
371+
" for i in range(4*n-1):\n",
372+
" m,n=map(int,input().split())\n",
373+
" l1.append(m) \n",
374+
" l2.append(n)\n",
375+
" print(reduce(lambda x, y: x ^ y,l1),reduce(lambda x, y: x ^ y,l2))"
377376
]
378377
},
379378
{
380-
"cell_type": "code",
381-
"execution_count": 5,
379+
"cell_type": "markdown",
382380
"metadata": {},
383-
"outputs": [
384-
{
385-
"data": {
386-
"text/plain": [
387-
"[1, 1, 4, 2, 9, 9, 4]"
388-
]
389-
},
390-
"execution_count": 5,
391-
"metadata": {},
392-
"output_type": "execute_result"
393-
}
394-
],
395381
"source": [
396-
"l1"
382+
"# [Doctor Chef](https://www.codechef.com/JULY20B/problems/DRCHEF)"
397383
]
398384
},
399385
{
400386
"cell_type": "code",
401-
"execution_count": 6,
387+
"execution_count": 1,
402388
"metadata": {},
403389
"outputs": [
404390
{
405-
"data": {
406-
"text/plain": [
407-
"[1, 2, 6, 1, 6, 3, 3]"
408-
]
409-
},
410-
"execution_count": 6,
411-
"metadata": {},
412-
"output_type": "execute_result"
391+
"name": "stdin",
392+
"output_type": "stream",
393+
"text": [
394+
" 1\n",
395+
" 5 1\n",
396+
" 40 30 20 10 50\n"
397+
]
398+
},
399+
{
400+
"name": "stdout",
401+
"output_type": "stream",
402+
"text": [
403+
"49\n",
404+
"47\n",
405+
"43\n",
406+
"35\n",
407+
"19\n",
408+
"10\n"
409+
]
413410
}
414411
],
415412
"source": [
416-
"l2"
413+
"for _ in range(int(input())):\n",
414+
" n1,n2=map(int,input().split())\n",
415+
" a=list(map(int,input().split()))\n",
416+
" c=len(a)\n",
417+
" m=max(a)\n",
418+
" if (m-n2)>0:\n",
419+
" m-=n2\n",
420+
" n2*=2\n",
421+
" while m>0:\n",
422+
" c+=1\n",
423+
" print(m)\n",
424+
" if (m-n2)>0:\n",
425+
" m-=n2\n",
426+
" n2*=2\n",
427+
" else:\n",
428+
" break\n",
429+
" print(c)\n",
430+
" else:\n",
431+
" print(c)"
417432
]
418433
},
419434
{
420435
"cell_type": "code",
421-
"execution_count": 14,
436+
"execution_count": 2,
422437
"metadata": {},
423438
"outputs": [
424439
{
425440
"data": {
426441
"text/plain": [
427-
"'89'"
442+
"10"
428443
]
429444
},
430-
"execution_count": 14,
445+
"execution_count": 2,
431446
"metadata": {},
432447
"output_type": "execute_result"
433448
}
434449
],
435450
"source": [
436-
"s='789'\n",
437-
"s=s.replace('7','')\n",
438-
"s"
451+
"c"
452+
]
453+
},
454+
{
455+
"cell_type": "markdown",
456+
"metadata": {},
457+
"source": [
458+
"<div class=\"LI-profile-badge\" data-version=\"v1\" data-size=\"medium\" data-locale=\"en_US\" data-type=\"horizontal\" data-theme=\"dark\" data-vanity=\"keshavsingh4522\"><a class=\"LI-simple-link\" href='https://in.linkedin.com/in/keshavsingh4522?trk=profile-badge'>Keshav Singh</a></div>"
439459
]
440460
},
441461
{
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from functools import reduce
2+
for _ in range(int(input())):
3+
n=int(input())
4+
l1=[]
5+
l2=[]
6+
for i in range(4*n-1):
7+
m,n=map(int,input().split())
8+
l1.append(m)
9+
l2.append(n)
10+
print(reduce(lambda x, y: x ^ y,l1),reduce(lambda x, y: x ^ y,l2))

0 commit comments

Comments
 (0)