diff --git a/IEEExtreme11.0/Fill the Pixel.cpp b/IEEExtreme11.0/Fill the Pixel.cpp new file mode 100644 index 0000000..66bff4d --- /dev/null +++ b/IEEExtreme11.0/Fill the Pixel.cpp @@ -0,0 +1,112 @@ +#include +#include +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 > N >> M; + for (int j = 0; j> str; + for (int k = 0; k + +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; +} \ No newline at end of file diff --git a/IEEExtreme11.0/Math_challenge/math_challenge.py b/IEEExtreme11.0/Math_challenge/math_challenge.py new file mode 100644 index 0000000..5a18f5e --- /dev/null +++ b/IEEExtreme11.0/Math_challenge/math_challenge.py @@ -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) + diff --git a/IEEExtreme11.0/Math_challenge/math_challenge_bigint.cpp b/IEEExtreme11.0/Math_challenge/math_challenge_bigint.cpp new file mode 100644 index 0000000..1705825 --- /dev/null +++ b/IEEExtreme11.0/Math_challenge/math_challenge_bigint.cpp @@ -0,0 +1,438 @@ +#include +#include +#include +#include +#include +#include +using namespace std; + +typedef unsigned long long ull; + +// base and base_digits must be consistent +const int base = 1000000000; +const int base_digits = 9; + +struct bigint { + vector a; + int sign; + + bigint() : + sign(1) { + } + + bigint(long long v) { + *this = v; + } + + bigint(const string &s) { + read(s); + } + + void operator=(const bigint &v) { + sign = v.sign; + a = v.a; + } + + void operator=(long long v) { + sign = 1; + if (v < 0) + sign = -1, v = -v; + for (; v > 0; v = v / base) + a.push_back(v % base); + } + + bigint operator+(const bigint &v) const { + if (sign == v.sign) { + bigint res = v; + + for (int i = 0, carry = 0; i < (int) max(a.size(), v.a.size()) || carry; ++i) { + if (i == (int) res.a.size()) + res.a.push_back(0); + res.a[i] += carry + (i < (int) a.size() ? a[i] : 0); + carry = res.a[i] >= base; + if (carry) + res.a[i] -= base; + } + return res; + } + return *this - (-v); + } + + bigint operator-(const bigint &v) const { + if (sign == v.sign) { + if (abs() >= v.abs()) { + bigint res = *this; + for (int i = 0, carry = 0; i < (int) v.a.size() || carry; ++i) { + res.a[i] -= carry + (i < (int) v.a.size() ? v.a[i] : 0); + carry = res.a[i] < 0; + if (carry) + res.a[i] += base; + } + res.trim(); + return res; + } + return -(v - *this); + } + return *this + (-v); + } + + void operator*=(int v) { + if (v < 0) + sign = -sign, v = -v; + for (int i = 0, carry = 0; i < (int) a.size() || carry; ++i) { + if (i == (int) a.size()) + a.push_back(0); + long long cur = a[i] * (long long) v + carry; + carry = (int) (cur / base); + a[i] = (int) (cur % base); + //asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base)); + } + trim(); + } + + bigint operator*(int v) const { + bigint res = *this; + res *= v; + return res; + } + + friend pair divmod(const bigint &a1, const bigint &b1) { + int norm = base / (b1.a.back() + 1); + bigint a = a1.abs() * norm; + bigint b = b1.abs() * norm; + bigint q, r; + q.a.resize(a.a.size()); + + for (int i = a.a.size() - 1; i >= 0; i--) { + r *= base; + r += a.a[i]; + int s1 = r.a.size() <= b.a.size() ? 0 : r.a[b.a.size()]; + int s2 = r.a.size() <= b.a.size() - 1 ? 0 : r.a[b.a.size() - 1]; + int d = ((long long) base * s1 + s2) / b.a.back(); + r -= b * d; + while (r < 0) + r += b, --d; + q.a[i] = d; + } + + q.sign = a1.sign * b1.sign; + r.sign = a1.sign; + q.trim(); + r.trim(); + return make_pair(q, r / norm); + } + + bigint operator/(const bigint &v) const { + return divmod(*this, v).first; + } + + bigint operator%(const bigint &v) const { + return divmod(*this, v).second; + } + + void operator/=(int v) { + if (v < 0) + sign = -sign, v = -v; + for (int i = (int) a.size() - 1, rem = 0; i >= 0; --i) { + long long cur = a[i] + rem * (long long) base; + a[i] = (int) (cur / v); + rem = (int) (cur % v); + } + trim(); + } + + bigint operator/(int v) const { + bigint res = *this; + res /= v; + return res; + } + + int operator%(int v) const { + if (v < 0) + v = -v; + int m = 0; + for (int i = a.size() - 1; i >= 0; --i) + m = (a[i] + m * (long long) base) % v; + return m * sign; + } + + void operator+=(const bigint &v) { + *this = *this + v; + } + void operator-=(const bigint &v) { + *this = *this - v; + } + void operator*=(const bigint &v) { + *this = *this * v; + } + void operator/=(const bigint &v) { + *this = *this / v; + } + + bool operator<(const bigint &v) const { + if (sign != v.sign) + return sign < v.sign; + if (a.size() != v.a.size()) + return a.size() * sign < v.a.size() * v.sign; + for (int i = a.size() - 1; i >= 0; i--) + if (a[i] != v.a[i]) + return a[i] * sign < v.a[i] * sign; + return false; + } + + bool operator>(const bigint &v) const { + return v < *this; + } + bool operator<=(const bigint &v) const { + return !(v < *this); + } + bool operator>=(const bigint &v) const { + return !(*this < v); + } + bool operator==(const bigint &v) const { + return !(*this < v) && !(v < *this); + } + bool operator!=(const bigint &v) const { + return *this < v || v < *this; + } + + void trim() { + while (!a.empty() && !a.back()) + a.pop_back(); + if (a.empty()) + sign = 1; + } + + bool isZero() const { + return a.empty() || (a.size() == 1 && !a[0]); + } + + bigint operator-() const { + bigint res = *this; + res.sign = -sign; + return res; + } + + bigint abs() const { + bigint res = *this; + res.sign *= res.sign; + return res; + } + + long long longValue() const { + long long res = 0; + for (int i = a.size() - 1; i >= 0; i--) + res = res * base + a[i]; + return res * sign; + } + + friend bigint gcd(const bigint &a, const bigint &b) { + return b.isZero() ? a : gcd(b, a % b); + } + friend bigint lcm(const bigint &a, const bigint &b) { + return a / gcd(a, b) * b; + } + + void read(const string &s) { + sign = 1; + a.clear(); + int pos = 0; + while (pos < (int) s.size() && (s[pos] == '-' || s[pos] == '+')) { + if (s[pos] == '-') + sign = -sign; + ++pos; + } + for (int i = s.size() - 1; i >= pos; i -= base_digits) { + int x = 0; + for (int j = max(pos, i - base_digits + 1); j <= i; j++) + x = x * 10 + s[j] - '0'; + a.push_back(x); + } + trim(); + } + + friend istream& operator>>(istream &stream, bigint &v) { + string s; + stream >> s; + v.read(s); + return stream; + } + + friend ostream& operator<<(ostream &stream, const bigint &v) { + if (v.sign == -1) + stream << '-'; + stream << (v.a.empty() ? 0 : v.a.back()); + for (int i = (int) v.a.size() - 2; i >= 0; --i) + stream << setw(base_digits) << setfill('0') << v.a[i]; + return stream; + } + + static vector convert_base(const vector &a, int old_digits, int new_digits) { + vector p(max(old_digits, new_digits) + 1); + p[0] = 1; + for (int i = 1; i < (int) p.size(); i++) + p[i] = p[i - 1] * 10; + vector res; + long long cur = 0; + int cur_digits = 0; + for (int i = 0; i < (int) a.size(); i++) { + cur += a[i] * p[cur_digits]; + cur_digits += old_digits; + while (cur_digits >= new_digits) { + res.push_back(int(cur % p[new_digits])); + cur /= p[new_digits]; + cur_digits -= new_digits; + } + } + res.push_back((int) cur); + while (!res.empty() && !res.back()) + res.pop_back(); + return res; + } + + typedef vector vll; + + static vll karatsubaMultiply(const vll &a, const vll &b) { + int n = a.size(); + vll res(n + n); + if (n <= 32) { + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + res[i + j] += a[i] * b[j]; + return res; + } + + int k = n >> 1; + vll a1(a.begin(), a.begin() + k); + vll a2(a.begin() + k, a.end()); + vll b1(b.begin(), b.begin() + k); + vll b2(b.begin() + k, b.end()); + + vll a1b1 = karatsubaMultiply(a1, b1); + vll a2b2 = karatsubaMultiply(a2, b2); + + for (int i = 0; i < k; i++) + a2[i] += a1[i]; + for (int i = 0; i < k; i++) + b2[i] += b1[i]; + + vll r = karatsubaMultiply(a2, b2); + for (int i = 0; i < (int) a1b1.size(); i++) + r[i] -= a1b1[i]; + for (int i = 0; i < (int) a2b2.size(); i++) + r[i] -= a2b2[i]; + + for (int i = 0; i < (int) r.size(); i++) + res[i + k] += r[i]; + for (int i = 0; i < (int) a1b1.size(); i++) + res[i] += a1b1[i]; + for (int i = 0; i < (int) a2b2.size(); i++) + res[i + n] += a2b2[i]; + return res; + } + + bigint operator*(const bigint &v) const { + vector a6 = convert_base(this->a, base_digits, 6); + vector b6 = convert_base(v.a, base_digits, 6); + vll a(a6.begin(), a6.end()); + vll b(b6.begin(), b6.end()); + while (a.size() < b.size()) + a.push_back(0); + while (b.size() < a.size()) + b.push_back(0); + while (a.size() & (a.size() - 1)) + a.push_back(0), b.push_back(0); + vll c = karatsubaMultiply(a, b); + bigint res; + res.sign = sign * v.sign; + for (int i = 0, carry = 0; i < (int) c.size(); i++) { + long long cur = c[i] + carry; + res.a.push_back((int) (cur % 1000000)); + carry = (int) (cur / 1000000); + } + res.a = convert_base(res.a, 6, base_digits); + res.trim(); + return res; + } +}; + + + + + + + + + + + + + + + + + + + +bigint combo(ull n, ull k) { + bigint res = 1; + + // Since C(n, k) = C(n, n-k) + if ( k > n - k ) + k = n - k; + + cout << "a " < 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); + + bigint comb; + // ull res = 1; + if (a != 1){ + comb = combo(b, c); + } else { + comb = 1; + } + ull res = power(a, comb); + + // for (ull i = 1; i <= comb; i++) + // res = (res*a) % M; + + printf("%llu\n", res); + + } + + return 0; +} \ No newline at end of file diff --git a/IEEExtreme11.0/Running Up Stairs.py b/IEEExtreme11.0/Running Up Stairs.py new file mode 100644 index 0000000..3664814 --- /dev/null +++ b/IEEExtreme11.0/Running Up Stairs.py @@ -0,0 +1,18 @@ +def fibonacci(n): + a = 1 + b = 1 + if n == 0: + return a + elif n == 1: + return b + else: + for i in range(2,n+1): + c = a + b + a = b + b = c + return b + +T = int(input()) +for t in range(T): + N = int(input()) + print(fibonacci(N)) diff --git a/IEEExtreme11.0/blackgate_penitentiary.py b/IEEExtreme11.0/blackgate_penitentiary.py new file mode 100644 index 0000000..d3fdb28 --- /dev/null +++ b/IEEExtreme11.0/blackgate_penitentiary.py @@ -0,0 +1,30 @@ +def sortSecond(val): + return val[1] + +def sortFirst(val): + return val[0] + +n = int(input()) +al = [] +for i in range(n): + one = input() + one = one.split(" ") + one[1] = int(one[1]) + al.append(one) + +al.sort(key = sortFirst) +al.sort(key = sortSecond) +al.append(['a', 251]) + +point = 0 +print(al[point][0], end = "") +while point < n: + start = point + 1 + while al[point][1] == al[point + 1][1]: + print(" " + al[point+1][0], end = "") + point += 1 + print("", start, "", (point+1)) + if point + 1 == n: + break + print(al[point+1][0], end = "") + point += 1 diff --git a/IEEExtreme11.0/fibonacci.py b/IEEExtreme11.0/fibonacci.py new file mode 100644 index 0000000..08fb2ee --- /dev/null +++ b/IEEExtreme11.0/fibonacci.py @@ -0,0 +1,20 @@ +def fibonacci(n): + a = 1 + b = 1 + if n == 0: + return a + elif n == 1: + return b + else: + for i in range(2,n+1): + c = a + b + a = b + b = c + return b + +t = int(input()) +for i in range(t): + m = int(input()) + n = (m)%60 + fibn = fibonacci(n) + print(fibn%10) \ No newline at end of file diff --git a/IEEExtreme11.0/recXor/recXor (full score).cpp b/IEEExtreme11.0/recXor/recXor (full score).cpp new file mode 100644 index 0000000..0c302f1 --- /dev/null +++ b/IEEExtreme11.0/recXor/recXor (full score).cpp @@ -0,0 +1,41 @@ +#include +#include + +using namespace std; + +typedef long long ll; + +ll xx(ll n) +{ + if (n % 4 == 0) return n; + if (n % 4 == 1) return 1; + if (n % 4 == 2) return n + 1; + return 0; +} + +int main( void ) { + int T; + scanf("%d", &T ); + for( int t = 1; t <= T; t++ ) { + ll l, h, n, d1, d2; + scanf("%lld%lld%lld%lld%lld", &l, &h, &n, &d1, &d2 ); + ll first = xx( n + l* h - 1 ) ^ xx( n - 1 ); + ll second = 0; + ll x1, y1, x2, y2; + x1 = ( d1 - n ) / l + 1; + y1 = (d1 - n + 1 ) - ( x1 - 1 ) * l; + x2 = ( d2 - n ) / l + 1; + y2 = ( d2 - n + 1 ) - ( x2 - 1 ) * l; + if( x1 > x2 ) swap( x1, x2 ); + if( y1 > y2 ) swap( y1, y2 ); + + for( int i = x1; i <= x2; i++ ) { + ll left = n + y1 - 1 + ( i - 1 ) * l; + ll right = n + y2 + ( i - 1 ) * l - 1; + second ^= xx( right ) ^ xx( left - 1 ); + } + ll res = first ^ second; + printf("%lld\n", res ); + } + return 0; +} diff --git a/IEEExtreme11.0/recXor/recxor_del.py b/IEEExtreme11.0/recXor/recxor_del.py new file mode 100644 index 0000000..d4b390a --- /dev/null +++ b/IEEExtreme11.0/recXor/recxor_del.py @@ -0,0 +1,34 @@ +times = int(input()) +for w in range(times): + inp = input() + inp = inp.split(" ") + l = int(inp[0]) + h = int(inp[1]) + n = int(inp[2]) + d1 = int(inp[3]) + d2 = int(inp[4]) + res = 0 + + if not(((d1-n+1)%l == 0) or ((d2-n+1)%l == 0)): + b = int((d2-n+1)/l) - int ((d1-n+1)/l) + 1 + a = abs(((d1-n+1)%l) - ((d2-n+1)%l)) + 1 + if ((d1 - n + 1)%l) > (d2 - n + 1)%l: + d1, d2 = d1-a+1, d2+a-1 + elif ((d1-n+1)%l) == 0: + b = int((d2-n+1)/l) - int ((d1-n+1)/l) + 2 + a = abs(l - ((d2-n+1)%l)) + 1 + d1, d2 = d1-a+1, d2+a-1 + elif ((d2-n+1)%l) == 0: + b = int((d2-n+1)/l) - int ((d1-n+1)/l) + 2 + a = abs(l - ((d1-n+1)%l)) + 1 + + + source = list(range(n, n+l*h)) + + for i in range(b): + del source[(d1 + i*(l-a)- n):((d1 + i*(l-a))+a- n)] + + for i in source: + res = res^i + + print(res) \ No newline at end of file diff --git a/IEEExtreme11.0/recXor/recxor_for.py b/IEEExtreme11.0/recXor/recxor_for.py new file mode 100644 index 0000000..40864ac --- /dev/null +++ b/IEEExtreme11.0/recXor/recxor_for.py @@ -0,0 +1,39 @@ +times = int(input()) +for w in range(times): + inp = input() + inp = inp.split(" ") + l = int(inp[0]) + h = int(inp[1]) + n = int(inp[2]) + d1 = int(inp[3]) + d2 = int(inp[4]) + res = 0 + + if not(((d1-n+1)%l == 0) or ((d2-n+1)%l == 0)): + b = int((d2-n+1)/l) - int ((d1-n+1)/l) + 1 + a = abs(((d1-n+1)%l) - ((d2-n+1)%l)) + 1 + if ((d1 - n + 1)%l) > (d2 - n + 1)%l: + d1, d2 = d1-a+1, d2+a-1 + elif ((d1-n+1)%l) == 0: + b = int((d2-n+1)/l) - int ((d1-n+1)/l) + 2 + a = abs(l - ((d2-n+1)%l)) + 1 + d1, d2 = d1-a+1, d2+a-1 + elif ((d2-n+1)%l) == 0: + b = int((d2-n+1)/l) - int ((d1-n+1)/l) + 2 + a = abs(l - ((d1-n+1)%l)) + 1 + + + for i in range(n, d1): + res = res^i + + for i in range(b): + if n + l*h - d1+i*l < l: + break + else: + for j in range(a, l): + res = res^(j+d1+i*l) + + for i in range(d2+l-a+1, n + l*h): + res = res^i + + print(res) \ No newline at end of file diff --git a/IEEExtreme11.0/rumour/roumor 100.py b/IEEExtreme11.0/rumour/roumor 100.py new file mode 100644 index 0000000..77003c9 --- /dev/null +++ b/IEEExtreme11.0/rumour/roumor 100.py @@ -0,0 +1,51 @@ +from math import log + +q = int(input()) +for i in range(q): + a, b = map(int, input().split()) + ha = int(log(a, 2)) + hb = int(log(b, 2)) + if ha < hb: + maxh = hb + maxn = b + minh = ha + minn = a + else: + maxh = ha + maxn = a + minh = hb + minn = b + + c = 0 + + for j in range(1, maxh-minh+1): + maxn = maxn//2 + c += 1 + + + while minn != maxn: + #general case + gay = int(log(abs(maxn-minn))) + if gay != 0: + maxn = maxn//(2**gay) + minn = minn//(2**gay) + c += 2*gay + else: + c += 2 + maxn = maxn//2 + minn = minn//2 + #Minimum required optimization + # if abs(maxn-minn)>3: + # maxn = maxn//8 + # minn = minn//8 + # c += 6 + # elif abs(maxn-minn)>1: + # maxn = maxn//4 + # minn = minn//4 + # c += 4 + # else: + # maxn = maxn//2 + # minn = minn//2 + # c += 2 + + print(c) diff --git a/IEEExtreme11.0/rumour/rumour.cpp b/IEEExtreme11.0/rumour/rumour.cpp new file mode 100644 index 0000000..33df551 --- /dev/null +++ b/IEEExtreme11.0/rumour/rumour.cpp @@ -0,0 +1,41 @@ +#include +#include + +using namespace std; + +int main() { + unsigned long long q,a,b,ha,hb,maxh,minh,maxn,minn,c; + scanf("%llu", &q); + for (unsigned long long i = 0; i < q; i++){ + scanf("%llu%llu", &a, &b); + ha = log2(a); + hb = log2(b); + if (ha < hb) { + maxh = hb; + maxn = b; + minh = ha; + minn = a; + } else { + maxh = ha; + maxn = a; + minh = hb; + minn = b; + } + c = 0; + while (minh ans): + ans = tempAns + else: + arr[i] = '0' + i += 1 + +print('A ' + ' '.join(arr)) diff --git a/IEEExtreme13.0/Charlie New PC.py b/IEEExtreme13.0/Charlie New PC.py new file mode 100644 index 0000000..8feb6dd --- /dev/null +++ b/IEEExtreme13.0/Charlie New PC.py @@ -0,0 +1,74 @@ +from itertools import product + +def anycomb1(item1): + return (comb for comb in product(item1)) + +def anycomb2(item1, item2): + return (comb for comb in product(item1, item2)) + +def anycomb3(item1, item2, item3): + return (comb for comb in product(item1, item2, item3)) + +def anycomb4(item1, item2, item3, item4): + return (comb for comb in product(item1, item2, item3, item4)) + +def anycomb5(item1, item2, item3, item4, item5): + return (comb for comb in product(item1, item2, item3, item4, item5)) + +def anycomb6(item1, item2, item3, item4, item5, item6): + return (comb for comb in product(item1, item2, item3, item4, item5, item6)) + +def anycomb7(item1, item2, item3, item4, item5, item6, item7): + return (comb for comb in product(item1, item2, item3, item4, item5, item6, item7)) + +def anycomb8(item1, item2, item3, item4, item5, item6, item7, item8): + return (comb for comb in product(item1, item2, item3, item4, item5, item6, item7, item8)) + +def anycomb9(item1, item2, item3, item4, item5, item6, item7, item8, item9): + return (comb for comb in product(item1, item2, item3, item4, item5, item6, item7, item8, item9)) + +def anycomb10(item1, item2, item3, item4, item5, item6, item7, item8, item9, item10): + return (comb for comb in product(item1, item2, item3, item4, item5, item6, item7, item8, item9, item10)) + +def totalvalue(comb): + totwt = totval = 0 + for wt in comb: + totwt += wt + return (totwt) if totwt <= max_cost else 0 + +n = int(input()) + +for test in range(n): + max_cost = int(input()) + components = int(input()) + opt4each = input() + opts = [] + for i in range(components): + temp_opts = input().split(' ') + temp_opts.append(str(3000000000)) + temp_opts = tuple(list(map(int, temp_opts))) + opts.append(temp_opts) + + + if(components == 1): + bagged = max(anycomb1(opts[0]), key=totalvalue) + elif(components == 2): + bagged = max(anycomb2(opts[0], opts[1]), key=totalvalue) + elif(components == 3): + bagged = max(anycomb3(opts[0], opts[1], opts[2]), key=totalvalue) + elif(components == 4): + bagged = max(anycomb4(opts[0], opts[1], opts[2], opts[3]), key=totalvalue) + elif(components == 5): + bagged = max(anycomb5(opts[0], opts[1], opts[2], opts[3], opts[4]), key=totalvalue) + elif(components == 6): + bagged = max(anycomb6(opts[0], opts[1], opts[2], opts[3], opts[4], opts[5]), key=totalvalue) + elif(components == 7): + bagged = max(anycomb7(opts[0], opts[1], opts[2], opts[3], opts[4], opts[5], opts[6]), key=totalvalue) + elif(components == 8): + bagged = max(anycomb8(opts[0], opts[1], opts[2], opts[3], opts[4], opts[5], opts[6], opts[7]), key=totalvalue) + elif(components == 9): + bagged = max(anycomb9(opts[0], opts[1], opts[2], opts[3], opts[4], opts[5], opts[6], opts[7], opts[8]), key=totalvalue) + elif(components == 10): + bagged = max(anycomb10(opts[0], opts[1], opts[2], opts[3], opts[4], opts[5], opts[6], opts[7], opts[8], opts[9]), key=totalvalue) + wt = totalvalue(bagged) + print(wt) diff --git a/IEEExtreme13.0/Concentration Game.py b/IEEExtreme13.0/Concentration Game.py new file mode 100644 index 0000000..f72cb9f --- /dev/null +++ b/IEEExtreme13.0/Concentration Game.py @@ -0,0 +1,27 @@ +n = int(input()) +if n == -1: + print(-1) + +arr = [] +for i in range(1, 2*n + 1, 2): + print(i, i+1) + resp = input() + if resp == 'MATCH': + arr.append(0) + arr.append(0) + elif resp == '-1': + print(-1) + else: + resp = resp.split(' ') + arr.append(int(resp[0])) + arr.append(int(resp[1])) + +for i in range(1, n+1): + res_list = [j for j, value in enumerate(arr) if value == i] + if res_list: + arr[res_list[0]] = arr[res_list[1]] = 0 + print(res_list[0]+1, res_list[1]+1) + resp = input() + if resp == '-1': + print(-1) +print(-1) diff --git a/IEEExtreme13.0/Lexical Addition.py b/IEEExtreme13.0/Lexical Addition.py new file mode 100644 index 0000000..d431ced --- /dev/null +++ b/IEEExtreme13.0/Lexical Addition.py @@ -0,0 +1,31 @@ +sab = input().split(' ') +s = int(sab[0]) +a = int(sab[1]) +b = int(sab[2]) + +res = [] + +def funccc(a, b, s): + if b < a: + return False + times = s // b + if s%b >= a: + res.append(times * (str(b)+' ')) + res.append(str(s%b)+ ' ') + return True + elif s%b == 0: + res.append(times * (str(b)+' ')) + return True + else: + temp = times - (a//((s%b)+1)) + if times > 1: + res.append(temp * (str(b)+' ')) + return funccc(a, b-(a//((s%b)+1)), s - temp*b) + +bool = funccc(a, b, s) +if bool: + res.reverse() + print('YES') + print(''.join(res)) +else: + print('NO') diff --git a/IEEExtreme13.0/Minimum Permutation.py b/IEEExtreme13.0/Minimum Permutation.py new file mode 100644 index 0000000..501aa15 --- /dev/null +++ b/IEEExtreme13.0/Minimum Permutation.py @@ -0,0 +1,19 @@ +nm = input().split(' ') +n = int(nm[0]) +m = int(nm[1]) + +arr = input().split(' ') +arr = list(map(int, arr)) +st = input().split(' ') +st = list(map(int, st)) + + +st.sort() +for s in st: + if (s > max(arr)): + arr.insert(len(arr), s) + else: + arr.insert(next(x[0] for x in enumerate(arr) if x[1]>=s), s) + +arr = list(map(str, arr)) +print(' '.join(arr)) diff --git a/IEEExtreme13.0/Xtreme Rappers.cpp b/IEEExtreme13.0/Xtreme Rappers.cpp new file mode 100644 index 0000000..4eb96e4 --- /dev/null +++ b/IEEExtreme13.0/Xtreme Rappers.cpp @@ -0,0 +1,19 @@ +#include + +using namespace std; + +int main(){ + unsigned long long int k, j; + scanf("%llu%llu", &k, &j); + + if (k <= j / 2){ + cout << k; + } else if (j <= k/2) { + cout << j; + } else { + unsigned long long int res = k/3 + j/3; + cout << res; + } + + return 0; +} \ No newline at end of file diff --git a/IEEExtreme13.0/Yin Yang.py b/IEEExtreme13.0/Yin Yang.py new file mode 100644 index 0000000..e83d72b --- /dev/null +++ b/IEEExtreme13.0/Yin Yang.py @@ -0,0 +1,10 @@ +n = int(input()) + +flag = 1 +for i in range(n): + if flag == 1: + print('y', end='') + flag = 0 + else: + print('Y', end='') + flag = 1