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

Week 1 (21 September 2020) solution #1

Open
wants to merge 6 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
40 changes: 40 additions & 0 deletions Week 1 (21 September 2020)/Solution ( ADAMAT )/ADAMAT.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <bits/stdc++.h>
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;i<n;i++)
for(j=0;j<n;j++)
scanf("%d" , &a[i][j]);
bool boolean[n];
for(j=0;j<n;j++)
{
if (a[0][j] == j+1)
boolean[j] = true;
else boolean[j] =false;
}

for (i=n-1;i>0;i--)
{
if(boolean[i] == false)
{
count++;
for(j=i; j>0; j--)
boolean[j] = boolean[j]?false:true;
}
}

printf("%d\n", count);
}


return 0;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions Week 1 (21 September 2020)/Solution ( CHFNSWAP )/CHFNSWAP.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <bits/stdc++.h>
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;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions Week 1 (21 September 2020)/Solution ( CRDGAME )/CRDGAME.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <bits/stdc++.h>
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;i<n;i++)
{
scanf("%lld %lld",&a,&b);
sa = calc(a); sb=calc(b);

if (sa==sb){
pointa += 1;
pointb += 1;
}
else sa>sb?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;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.