Skip to content
Open
Show file tree
Hide file tree
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
104 changes: 104 additions & 0 deletions Flood_FIll_Algo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Python3 implementation of the approach

# Function that returns true if
# the given pixel is valid
def isValid(screen, m, n, x, y, prevC, newC):
if x<0 or x>= m\
or y<0 or y>= n or\
screen[x][y]!= prevC\
or screen[x][y]== newC:
return False
return True


# FloodFill function
def floodFill(screen,
m, n, x,
y, prevC, newC):
queue = []

# Append the position of starting
# pixel of the component
queue.append([x, y])

# Color the pixel with the new color
screen[x][y] = newC

# While the queue is not empty i.e. the
# whole component having prevC color
# is not colored with newC color
while queue:

# Dequeue the front node
currPixel = queue.pop()

posX = currPixel[0]
posY = currPixel[1]

# Check if the adjacent
# pixels are valid
if isValid(screen, m, n,
posX + 1, posY,
prevC, newC):

# Color with newC
# if valid and enqueue
screen[posX + 1][posY] = newC
queue.append([posX + 1, posY])

if isValid(screen, m, n,
posX-1, posY,
prevC, newC):
screen[posX-1][posY]= newC
queue.append([posX-1, posY])

if isValid(screen, m, n,
posX, posY + 1,
prevC, newC):
screen[posX][posY + 1]= newC
queue.append([posX, posY + 1])

if isValid(screen, m, n,
posX, posY-1,
prevC, newC):
screen[posX][posY-1]= newC
queue.append([posX, posY-1])



# Driver code
screen =[
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 0, 0],
[1, 0, 0, 1, 1, 0, 1, 1],
[1, 2, 2, 2, 2, 0, 1, 0],
[1, 1, 1, 2, 2, 0, 1, 0],
[1, 1, 1, 2, 2, 2, 2, 0],
[1, 1, 1, 1, 1, 2, 1, 1],
[1, 1, 1, 1, 1, 2, 2, 1],
]

# Row of the display
m = len(screen)

# Column of the display
n = len(screen[0])

# Co-ordinate provided by the user
x = 4
y = 4

# Current color at that co-ordinate
prevC = screen[x][y]

# New color that has to be filled
newC = 3

floodFill(screen, m, n, x, y, prevC, newC)


# Printing the updated screen
for i in range(m):
for j in range(n):
print(screen[i][j], end =' ')
print()
68 changes: 68 additions & 0 deletions Pouring Water ICPC.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include <bits/stdc++.h>
#define GREEN "\033[32m"
#define MAGENTA "\033[35m"
#define RESET "\033[0m"
#define all(x) begin(x),end(x)
#define sz(x) (int)(x).size()
using namespace std;
#ifdef BCDBG
#define tcT template<typename T
tcT,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p) {return os<<"("<<p.first<<", "<<p.second<<")";}
tcT,typename U=typename enable_if<!is_same<T,string>::value,typename T::value_type>::type> ostream& operator<<(ostream &os,const T &v)
{os<<"\n{";string sep;for(const U &x:v)os<<sep<<x,sep=", ";return os<<'}';}
void debug_help() {cout<<RESET<<endl;}
tcT,typename... U> void debug_help(T t,U... u) {cout<<t;if(sizeof...(u))cout<<", ";debug_help(u...);}
int debug_dms[10],debug_md;
void debug_fill() {}
tcT,typename... U> void debug_fill(T t,U... u) {debug_dms[debug_md++]=t;debug_fill(u...);}
tcT> void debug_arr(T x,int d) {cout<<x;}
tcT> void debug_arr(T* arr,int d)
{cout<<"\n{";string sep;for(int i=0;i<debug_dms[d];i++)cout<<sep,sep=", ",debug_arr(arr[i],d+1);cout<<'}';if(d==0)cout<<RESET<<endl;}
#define dbg(...) cout<<MAGENTA<<__LINE__<<" ["<<#__VA_ARGS__<<"]: "<<GREEN,debug_help(__VA_ARGS__)
#define dba(arr,...) cout<<MAGENTA<<__LINE__<<" ["<<#arr<<"]: "<<GREEN,debug_md=0,debug_fill(__VA_ARGS__),debug_arr(arr,0)
#else
#define dbg(...)
#define dba(arr,...)
#endif
typedef long long ll;
typedef unsigned long long ull;
const char df = '\n';
int go(int A, int B, int c) {
int ct = 1, a = A, b = 0;
while (a != c && b != c) {
if (a == 0) {
a = A;
ct++;
} else if (b == B) {
b = 0;
ct++;
} else {
int m = min(B - b, a);
a -= m;
b += m;
ct++;
}
}
return ct;
}
void solve() {
int a, b, c;
cin >> a >> b >> c;
if (c % __gcd(a, b) || (c > a && c > b)) {
cout << -1 << df;
return;
}
cout << min(go(a, b, c), go(b, a, c)) << df;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int tt = 1;
cin >> tt;
for (int i = 1; i <= tt; i++) {
solve();
}
return 0;
}
Python
import math
131 changes: 129 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,129 @@
# HacktoberFest
Send merge request for the HAcktoberFests
[https://github.com/open-for-everyone/hacktoberfest2021/discussions/747](https://github.com/open-for-everyone/hacktoberfest2021/discussions/747)

<p align="center">
<a href="https://hacktoberfest.digitalocean.com/">
<img src="logo.png" width="90%">
</a>
</p>

<h1 align="center"> Hacktoberfest 2021 🎉</h1>
FREE FOR ALL , LEARNING and CELEBRATING OPEN SOURCE, This Hacktoberfest project exists to help you submit your first Pull Request!
Skip to content
Search or jump to…
Pull requests
Issues
Marketplace
Explore

/
Hacktoberfest-1
Public
0
0
528
Code
Pull requests
Actions
Projects
Wiki
Security
Insights
Settings
Hacktoberfest-1
/
README.md
in
master




## Your First Pull Request - Hacktoberfest
I created this project in the spirit of hacktoberfest so that you can do a very simple pull request and in the process you learn how to contribute to a project :smiley:
Note that this repository exists as a learning tool for new contributors to open-source, and pull requests to this won’t count toward Hacktoberfest! PR requests won't be accepted/merged.

### What is Hacktoberfest?
[Hacktoberfest](https://hacktoberfest.digitalocean.com/) is a month-long celebration of open source software. You have to register and make five pull requests to any github repo (including this one!) in the month of october. If you do that you get a tshirt :tshirt: and stickers for your laptop :computer: . Sounds interesting? Let's do it then!

### Wait...what is github?!

I get it. You are new to this whole thing. But don't worry, here is a great [guide](https://guides.github.com/activities/hello-world/) to help you understand.

### Contribution Guide

To Contribute in a proper way so that I can merge the pull request:

1. Star the repo! :star:

2. Fork it. (Important!) [What is that?](https://help.github.com/articles/fork-a-repo/)

3. Edit the README.md file.

4. Copy the below code and replace with your github user name. Add after the last one in the file.

* [yourusernamehere](https://github.com/yourusernamehere)

5. Commit with a message. ( Or write "ALL IS WELL!")

6. Make a pull request. [What is that?](https://help.github.com/articles/creating-a-pull-request-from-a-fork/)

7. Done! Welcome to the dark side!


## How to contribute to this project
## Choose from these tasks
### 1. Add your name
Add your name to the `CONTRIBUTORS.md` file using the below convention:

```markdown
#### Name: [YOUR NAME](GitHub link)
- Place: City, State, Country
- Bio: Who are you?
- GitHub: [GitHub account name](GitHub link)
```


### 2. Create a A 'CODE' / Script in any Language
Add a `hello_world_yourusername.xx` script to the `scripts` directory in any language of your choice! Here is an example:

```Javascript
// LANGUAGE: Javascript
// ENV: Node.js
// AUTHOR: Alice Chuang
// GITHUB: https://github.com/AliceWonderland

console.log('Hello, World!');

```


### 3. Add a profile page to the `profiles` directory



#### Choose one or all 3, make a pull request for your work and wait for it to be merged!

#### Happy Learning & Hacktoberfest :::
No file chosen
Attach files by dragging & dropping, selecting or pasting them.

Commit changes
Commit summary
Create README.md
Optional extended description
Add an optional extended description…
Commit directly to the master branch.
Create a new branch for this commit and start a pull request. Learn more about pull requests.

© 2021 GitHub, Inc.
Terms
Privacy
Security
Status
Docs
Contact GitHub
Pricing
API
Training
Blog
About
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.