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

Adding few solutions to Codechef problems #447

Open
wants to merge 1 commit 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
22 changes: 22 additions & 0 deletions Codechef/ADAKING.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdio.h>
int main(void) {
int t,n,k,r,i,j;
scanf("%d",&t);
while(t--){
scanf("%d",&k);
r=64-k;
for(i=1;i<=8;i++){
for(j=1;j<=8;j++){
if(i==8&&j==8)
{printf("O");}
else if(r)
{printf("X");r--;}
else
{ printf(".");}
}
printf("\n");
}
}
return 0;
}

41 changes: 41 additions & 0 deletions Codechef/ALPHABET.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//Author: Rakshit Naidu

#include <stdio.h>

int main(void) {
// your code goes here
char s[30],str[15];
scanf("%s",&s);
int x = strlen(s);
int t;
scanf("%d",&t);

while(t--)
{
scanf("%s",&str);
int i,j;
int l=strlen(str);
for(i=0;i<strlen(str);i++)
{
for(j=0;j<strlen(s);j++)
{
if(str[i]==s[j])
{
break;
}
}
if(j>=strlen(s))
{
printf("No\n");
break;
}
}
if(i>=strlen(str))
{
printf("Yes\n");
}
}

return 0;
}

25 changes: 25 additions & 0 deletions Codechef/BIGSALE .cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//BIGSALE - codechef

#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
//cout << "Hello world!" << endl;
int t;
cin>>t;
while(t--){
int n;
cin>>n;
double q[n];
double p[n],x[n],l=0;
for(int i=0;i<n;i++){
cin>>p[i]>>q[i]>>x[i];
l=l+(p[i]*x[i]*x[i]*q[i]*0.0001);
}
cout<<fixed<<setprecision(10)<<l<<endl;
}
return 0;
}

151 changes: 151 additions & 0 deletions Codechef/BIT2B.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
#include<bits/stdc++.h>

using namespace std;

#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 1000000
#define ll long long
#define db double
#define str string
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Forrev(i,s,e) for (ll i=(s); i>=(e); i--)
#define all(v) v.begin(),v.end()

#define vll vector<ll>
#define vs vector<string>
#define mapll map<ll,ll>
#define pll pair<ll,ll>
#define initialise(a, x) memset(a, x, sizeof(a))
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll,vector<ll> ,greater<ll>>

#define ff first
#define ss second
#define endl "\n"
#define mp make_pair
const ll mod=1e9 + 7;

ll takemod(ll a) {
return ((a%mod)+mod)%mod;
}

ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}

ll fast_exp(ll base, ll expo) {
ll res=1;
while(expo>0) {
if(expo&1) res=(res*base)%mod;
base=(base*base)%mod;
expo>>=1;}
return res;
}

ll modinv(ll a) {
return takemod(fast_exp(takemod(a), mod-2));
}


signed main()
{
fast_cin();
#ifndef ONLINE_JUDGE
freopen("C:/IO/in.txt", "r", stdin);
freopen("C:/IO/out.txt", "w", stdout);
#endif
ll t,n;
cin>>t;
For(l,0,t)
{
cin>>n;
ll arr[n];
For(i,0,n)
{
cin>>arr[i];
}

ll x;
cin>>x;

ll i=0,j=n-1,sum1=0,sum2=0;
ll sumarr[n];
memset(sumarr,0,sizeof(sumarr));

ll markarr[n];
memset(markarr,-1,sizeof(markarr));

while(i<=j)
{
if(i==j)
{
if(markarr[i]!=-1)
break;
ll ans1=0,ans2=0;
For(k,0,n)
{
//cout<<markarr[i]<<endl;
if(markarr[k]==1)
ans1++;
else if(markarr[k]==2)
ans2++;
}
//cout<<ans1<<"XX"<<ans2<<endl;
if(ans1>=ans2)
{
markarr[i]=1;
i++;
}
else
{
markarr[i]=2;
j--;
}
}
else
{
sum1=0,sum2=0;
sum2=arr[j];
markarr[j]=2;
while(i<j and sum1<x*sum2)
{
if(sum1+arr[i]-sumarr[i]>x*sum2)
{
sumarr[i]+=x*sum2-sum1;
sum1=sum2;
markarr[i]=1;
if(sumarr[i]==arr[i])
i++;
break;
}
else
{
sum1+=arr[i]-sumarr[i];
markarr[i]=1;
i++;
}
}
j--;
//cout<<i<<" "<<j<<endl;

}

}

ll ans1=0,ans2=0;
For(k,0,n)
{
//cout<<markarr[k]<<" ";
if(markarr[k]==1)
ans1++;
else if(markarr[k]==2)
ans2++;
}
cout<<ans1<<" "<<ans2<<endl;
}

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

//important constants
#define pi M_PI
#define mod 1000000007
#define maX(a,b) ((a)>(b)?(a):(b))
#define miN(a,b) ((a)<(b)?(a):(b))

#ifdef ONLINE_JUDGE
#define MAX 200005
#else
#define MAX 100000
#endif

int a[MAX],b[MAX];
char s[MAX],r[MAX];
int test;

int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif

int t,n,m,k,l,x,y,z,flag,count,d,mx,mn;
long long int sum,prod;

scanf("%d",&test);

while(test--){
flag=0;
// scanf("%d",&n);
scanf("%d%d",&n,&m);

if(n%2 && m%2){
if(abs(n-m)==2)
flag=1;
}else if(n%2){
if(m-n==1)
flag=1;
}else if(m%2){
if(n-m==1)
flag=1;
}else{
if(abs(n-m)==2)
flag=1;
}
if(flag) printf("YES\n");
else printf("NO\n");

}
return 0;
}
39 changes: 39 additions & 0 deletions Codechef/CANDY123.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//Author: Rakshit Naidu

#include <stdio.h>
int func(int x,int y,int r);

int main(void) {
// your code goes here
int t;
scanf("%d",&t);

while(t--)
{
int a,b;
scanf("%d %d",&a,&b);
int rem=2;
func(a,b,rem);
}
return 0;
}
int func(int x,int y,int r)
{
x = x - (r/2);
r++;
r++;
if(x<0)
{
printf("Bob\n");
return;
}
y = y - (r/2);
r++;
r++;
if(y<0)
{
printf("Limak\n");
return;
}
return func(x,y,r);
}
26 changes: 26 additions & 0 deletions Codechef/CHCHCL.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//Author: Rakshit Naidu

#include <stdio.h>

int main(void) {
// your code goes here
int t;
scanf("%d",&t);

while(t--)
{
int m,n;
scanf("%d %d",&m,&n);

if(m%2==0||n%2==0)
{
printf("Yes\n");
}
else
{
printf("No\n");
}
}
return 0;
}

Loading