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

Old Ieeextreme solutions #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
112 changes: 112 additions & 0 deletions IEEExtreme11.0/Fill the Pixel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#include<iostream>
#include <cstring>
using namespace std;
int t,M,N;
char screen1[1000][1000];
char screen2[1000][1000];
char screen3[1000][1000];
// A recursive function to replace previous color 'prevC' at '(x, y)'
// and all surrounding pixels of (x, y) with new color 'newC' and
void floodFillUtil1(int x, int y, int prevC, int newC)
{
// Base cases
if (x < 0 || x >= M || y < 0 || y >= N)
return;
if (screen1[x][y] != prevC)
return;
if (screen1[x][y] == newC)
return;

// Replace the color at (x, y)
screen1[x][y] = newC;

// Recur for north, east, south and west
floodFillUtil1(x+1, y, prevC, newC);
floodFillUtil1(x-1, y, prevC, newC);
floodFillUtil1(x, y+1, prevC, newC);
floodFillUtil1(x, y-1, prevC, newC);
}

void floodFillUtil2(int x, int y, int prevC, int newC)
{
// Base cases
if (x < 0 || x >= M || y < 0 || y >= N)
return;
if (screen2[x][y] != prevC)
return;
if (screen2[x][y] == newC)
return;

// Replace the color at (x, y)
screen2[x][y] = newC;

// Recur for north, east, south and west
floodFillUtil2(x + 1, y + 1, prevC, newC);
floodFillUtil2(x - 1, y - 1, prevC, newC);
floodFillUtil2(x - 1, y + 1, prevC, newC);
floodFillUtil2(x + 1, y - 1, prevC, newC);
}


void floodFillUtil3(int x, int y, int prevC, int newC)
{
// Base cases
if (x < 0 || x >= M || y < 0 || y >= N)
return;
if (screen3[x][y] != prevC)
return;
if (screen3[x][y] == newC)
return;

// Replace the color at (x, y)
screen3[x][y] = newC;

// Recur for north, east, south and west
floodFillUtil3(x - 1, y - 1, prevC, newC);
floodFillUtil3(x - 1, y, prevC, newC);
floodFillUtil3(x - 1, y + 1, prevC, newC);
floodFillUtil3(x, y - 1, prevC, newC);
floodFillUtil3(x, y + 1, prevC, newC);
floodFillUtil3(x + 1, y - 1, prevC, newC);
floodFillUtil3(x + 1, y, prevC, newC);
floodFillUtil3(x + 1, y + 1, prevC, newC);
}

int main(){

cin >> t;
for (int i = 0; i <t; i++){
string str;
int c1 =0;
int c2 = 0;
int c3 = 0;
cin >> N >> M;
for (int j = 0; j<M; j++){
cin >> str;
for (int k = 0; k<N; k++){
screen1[j][k] = str.at(k);
}
}
memcpy (screen2, screen1, 1000*1000*sizeof(char));
memcpy (screen3, screen1, 1000*1000*sizeof(char));

for (int row =0; row < M; row++){
for (int col =0; col < N; col++){
if (screen1[row][col] == '1'){
floodFillUtil1(row, col, '1', '0');
c1 += 1;
}
if (screen2[row][col] == '1'){
floodFillUtil2(row, col, '1', '0');
c2 += 1;
}
if (screen3[row][col] == '1'){
floodFillUtil3(row, col, '1', '0');
c3 += 1;
}
}
}
cout << c1 << ' '<< c2 << ' ' << c3 << '\n';
}

}
61 changes: 61 additions & 0 deletions IEEExtreme11.0/Math_challenge/math_challenge.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;

ull combo(ull n, ull k) {
ull res = 1;

// Since C(n, k) = C(n, n-k)
if ( k > n - k )
k = n - k;

// Calculate value of [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
for (ull i = 0; i < k; ++i)
{
res *= (n - i);
res /= (i + 1);
}

return res;
}

ull power(ull x, ull y)
{
const unsigned int M = 1000000007;
ull res = 1; // Initialize result

while (y > 0)
{
if (y%2 == 1)
res = (res*x) % M;
y = y/2; // y = y/2
x = (x*x) % M;
}
return res;
}

int main() {
int t;
ull a, b, c;

scanf("%d", &t);

while (t--) {
scanf("%llu%llu%llu", &a, &b, &c);


// ull res = 1;
ull comb = combo(b, c);
ull res = power(a, comb);

// for (ull i = 1; i <= comb; i++)
// res = (res*a) % M;

printf("%llu\n", res);

}

return 0;
}
47 changes: 47 additions & 0 deletions IEEExtreme11.0/Math_challenge/math_challenge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from math import floor

def combo(n, k):
# since C(n, k) = C(n, n - k)
if(k > n - k):
k = n - k
# initialize result
res = 1
# Calculate value of
# [n * (n-1) *---* (n-k + 1)] / [k * (k-1) *----* 1]
for i in range(k):
res = res * (n - i)
res = res / (i + 1)
return res


def mpower(x, y) :
res = 1 # Initialize result
M = 1000000007

while (y > 0) :

# If y is odd, multiply
# x with result
if (y%2 == 1) :
res = (res * x) % M

# y must be even now
y = floor(y / 2)
print(y) # y = y/2
x = (x * x) % M

return res


t = int(input())
for i in range(t):
abc = input()
a_b_c = abc.split(" ")
a = int(a_b_c[0])
b = int(a_b_c[1])
c = int(a_b_c[2])

comb = combo(b, c)
res = mpower(a, floor(comb))
print(res)

Loading