diff --git a/Week 1 (21 September 2020)/Solution ( ADAMAT )/ADAMAT.cpp b/Week 1 (21 September 2020)/Solution ( ADAMAT )/ADAMAT.cpp new file mode 100644 index 0000000..2dfa908 --- /dev/null +++ b/Week 1 (21 September 2020)/Solution ( ADAMAT )/ADAMAT.cpp @@ -0,0 +1,40 @@ +#include +using namespace std; + +int main() { + // your code goes here + int t,n,i,j,count; + + scanf("%d",&t); + while(t--){ + + scanf("%d",&n); + count = 0; + int a[n][n]; + for(i=0;i0;i--) + { + if(boolean[i] == false) + { + count++; + for(j=i; j>0; j--) + boolean[j] = boolean[j]?false:true; + } + } + + printf("%d\n", count); + } + + + return 0; +} diff --git a/Week 1 (21 September 2020)/Solution ( ADAMAT )/ADAMAT.png b/Week 1 (21 September 2020)/Solution ( ADAMAT )/ADAMAT.png new file mode 100644 index 0000000..358153d Binary files /dev/null and b/Week 1 (21 September 2020)/Solution ( ADAMAT )/ADAMAT.png differ diff --git a/Week 1 (21 September 2020)/Solution ( CHFNSWAP )/CHFNSWAP.cpp b/Week 1 (21 September 2020)/Solution ( CHFNSWAP )/CHFNSWAP.cpp new file mode 100644 index 0000000..144605e --- /dev/null +++ b/Week 1 (21 September 2020)/Solution ( CHFNSWAP )/CHFNSWAP.cpp @@ -0,0 +1,42 @@ +#include +using namespace std; + +long long pivot(long long n) +{ + long double nn = n; + return (long long)(((-2.0)+(sqrt(4.0+8*(n*n+n)))) / 4.0); // from quad equation 2x^2 + 2x - (n^2 + n) = 0 + // which comes from (x(x+1))/2= (n(n+1)/2)/2 and long long takes its floor value +} + +long long nc2 (long long n){ + return (n*n - n)/2; +} + +int main() { + // your code goes here + long long t,n, sumn, x, ans; + scanf("%lld", &t); + while(t--){ + ans=0; + scanf("%lld",&n); + sumn = (n*(n+1))/2; + + if(sumn%2==1){ // not possible case sum=odd + ans = 0; + } + else{ + x = pivot(n); + ans += (n-x); + + if ( (x*x+x)*2 == (n*n + n) ) + ans += nc2(x) + nc2(n-x); + // if pivot actually exists before, then we can do all possible swaps in grp1 and all in grp2 + } + + printf("%lld\n", ans); + + } + + + return 0; +} diff --git a/Week 1 (21 September 2020)/Solution ( CHFNSWAP )/CHFNSWAP1.png b/Week 1 (21 September 2020)/Solution ( CHFNSWAP )/CHFNSWAP1.png new file mode 100644 index 0000000..834407f Binary files /dev/null and b/Week 1 (21 September 2020)/Solution ( CHFNSWAP )/CHFNSWAP1.png differ diff --git a/Week 1 (21 September 2020)/Solution ( CHFNSWAP )/CHFNSWAP2.png b/Week 1 (21 September 2020)/Solution ( CHFNSWAP )/CHFNSWAP2.png new file mode 100644 index 0000000..956f2a8 Binary files /dev/null and b/Week 1 (21 September 2020)/Solution ( CHFNSWAP )/CHFNSWAP2.png differ diff --git a/Week 1 (21 September 2020)/Solution ( CRDGAME )/CRDGAME.cpp b/Week 1 (21 September 2020)/Solution ( CRDGAME )/CRDGAME.cpp new file mode 100644 index 0000000..6030856 --- /dev/null +++ b/Week 1 (21 September 2020)/Solution ( CRDGAME )/CRDGAME.cpp @@ -0,0 +1,46 @@ +#include +using namespace std; + +int calc(long long n){ + int sum=0; + while(n!=0) + { + sum = sum + n%10; + n = n/10; + } + return sum; +} + +int main() { + // your code goes here + + int t,n,i, sa,sb, pointa, pointb; + long long a,b; + scanf("%d", &t); + + while(t--){ + + scanf("%d", &n); + pointa=0; pointb=0; + + for(i=0;isb?pointa+=1:pointb+=1; + } + if(pointa > pointb) + printf("0 %d\n", pointa); + else if (pointa < pointb) + printf("1 %d\n", pointb); + else printf("2 %d\n", pointb); + + } + + return 0; +} diff --git a/Week 1 (21 September 2020)/Solution ( CRDGAME )/CRDGAME.png b/Week 1 (21 September 2020)/Solution ( CRDGAME )/CRDGAME.png new file mode 100644 index 0000000..866c1c0 Binary files /dev/null and b/Week 1 (21 September 2020)/Solution ( CRDGAME )/CRDGAME.png differ