Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added cp files for Python #214

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions src/pages/sheet/competitve-programming-python.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
layout: ../../layouts/CheatSheet.astro
title: "Competitive Programming Python Cheatsheet"
---

## Synopsis

Competitive programming is a mind sport usually held over the Internet or a local network, involving participants trying to program according to provided specifications. Competitive programming is recognized and supported by several multinational software and Internet companies.

There are many different types of competitive programming competitions, including:

| Type | Description |
| ----------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [ACM-ICPC](https://icpc.baylor.edu/) | The ACM International Collegiate Programming Contest (ICPC) is an annual multi-tiered competitive programming competition among the universities of the world. |
| [Google Code Jam](https://codingcompetitions.withgoogle.com/codejam) | Google Code Jam is a programming competition organized and run by Google. |
| [Google Kick Start](https://codingcompetitions.withgoogle.com/kickstart) | Google Kick Start is a global online coding competition, consisting of three-hour rounds of algorithmic puzzles designed by Google engineers and held virtually. |
| [Google Hash Code](https://codingcompetitions.withgoogle.com/hashcode) | Google Hash Code is a team-based programming competition, organized by Google for students and professionals around the world. |
| [Facebook Hacker Cup](https://www.facebook.com/codingcompetitions/hacker-cup) | Facebook Hacker Cup is a worldwide programming competition organized by Facebook. |

## standard-python-templates

### standard libraries to import
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why lowercase?


```python
from math import sqrt, ceil, floor
from time import time
from itertools import count, combinations
from functools import reduce
```

### template-for-gcd

```python
def gcd(a, b):
if b == 0:
return a
return gcd(b, a%b)

```

### sieve-of-eratosthenes

```python
def SieveOfEratosthenes(n):

nums = {}
for i in range(2, n+1):
nums[i] = 1

for i in nums:
if nums[i] == 1:
k = 2
m = k*i
while m <= n:
k+=1
nums[m] = 0
m = k*i

ans = []
for k in nums:
if nums[k] == 1:
ans.append(k)

return ans
```

### prime-factorization

```python
def PrimeFact(n):
factors = {}
for i in range(2, int(sqrt(n)) + 1):
c = 0
while n % i == 0:
n//=i
c+=1
factors[i] = c
if n > 1:
factors[n] = 1
return factors
```