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

Added some codeforces solutions #118

Open
wants to merge 1 commit into
base: main
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
35 changes: 35 additions & 0 deletions Codeforces_Solutions/Fedor_and_New_Game.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <bits/stdc++.h>
using namespace std;

int bitdiff(int x,int y,int n){
int ct=0;
int i=0;
while(i<=n){
int a=x&1;
int b=y&1;
if(a!=b) ct++;
x=x>>1;
y=y>>1;
i++;
}
return ct;
}
int main(){
int ct=0;
int n,m,k;
cin>>n>>m>>k;
int a[m+1];
for(int i=0;i<m+1;i++){
cin>>a[i];
}
for(int i=0;i<m;i++){
if(bitdiff(a[i],a[m],n)<=k) ct++;
}
cout<<ct<<endl;





return 0;
}
32 changes: 32 additions & 0 deletions Codeforces_Solutions/Queue_At_the_School.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <bits/stdc++.h>
using namespace std;

int main(){

int n,k;
cin>>n>>k;
string s;
cin>>s;
int hhh=223;
int ct=0;
for(int j=0;j<k;j++){
for(int i=0;i<n-1;i++){
if(s[i]=='B' && s[i+1]=='G'){
s[i]='G';
s[i+1]='B';
i++;
}



}
}

cout<<s<<endl;





return 0;
}
31 changes: 31 additions & 0 deletions Codeforces_Solutions/Random_Teams.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <bits/stdc++.h>
using namespace std;
int minS(long long int a,long long int b){
if(a>b) return b;
else return a;
}
int main(){
long long int n,m;
cin>>n>>m;


long long int d=n-(m-1)-1;

long long int max=d*(d+1)/2;

long long int a=n/m;
long long int b=n%m;

long long int min=(a*(a+1)/2)*(n%m)+ ((a-1)*a/2)*(m-b);

cout<<min<<" "<<max<<endl;








return 0;
}
34 changes: 34 additions & 0 deletions Codeforces_Solutions/Xenia_and_Ringroad.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <bits/stdc++.h>
using namespace std;

int main(){

long long int n,k;
cin>>n>>k;
long long int a[k];
long long int c[k];
for(long long int i=0;i<k;i++){
cin>>a[i];
}
long long int sum=0;
for(long long int i=0;i<k-1;i++){
long long int d=a[i+1]-a[i];
if(d<0) sum+=n-a[i]+a[i+1];

else sum+=d;
}
for(long long int i=0;i<k-1;i++){
c[i]=a[i+1]-a[i];
}
sum+=a[0]-1;

cout<<sum<<endl;
cout<<endl;






return 0;
}
Empty file.