Skip to content

Commit

Permalink
Merge pull request shivaylamba#645 from thedrivingforc/master
Browse files Browse the repository at this point in the history
a list of handpicked sopj questions and codes to few of adhoc ones
  • Loading branch information
shivaylamba authored Oct 10, 2020
2 parents 1849b00 + 1e47b6e commit 3f6bc2c
Show file tree
Hide file tree
Showing 20 changed files with 754 additions and 0 deletions.
37 changes: 37 additions & 0 deletions SPOJ_LIST/ABSP1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include<bits/stdc++.h>

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fo(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
ll a[n];
fo(i,n)
cin>>a[i];
ll sum=0;
for(ll i=0;i<n;i++)
{
sum+=i*a[i]-(n-i-1)*a[i];
}
cout<<sum<<"\n";

}


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

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fo(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

ll t;
cin>>t;
for(int i=0;i<t;i++)
{
ll n;
cin>>n;
while(n%2==0)
{
n/=2;
}
cout<<"Case "<<(i+1)<<": "<<n<<"\n";
}


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

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fo(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;

ll a[]={1,4,6,5,2,0};
cout<<(a[(n-1)%6])<<"\n";

}


return 0;
}
/*******************************************************
WRONG QUESTION(ERROR)
**********************************************************/
47 changes: 47 additions & 0 deletions SPOJ_LIST/GIRLSNBS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include<bits/stdc++.h>

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fo(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

ll b,g;
while(cin>>g>>b && g!=-1)
{
ll ans=0;
ll k=g/(b+1);
ll l=b/(g+1);
if(g==b)
{
if(g==0 && b==0)
ans=0;
else
ans=1;
}
else if(g>b)
{
if(g%(b+1)!=0)
ans=1+k;
else
ans=k;
}
else
{
if(b%(g+1)!=0)
ans=1+l;
else
ans=l;
}
cout<<ans<<"\n";
}
return 0;
}
31 changes: 31 additions & 0 deletions SPOJ_LIST/MOHIB.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include<bits/stdc++.h>

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fo(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

ll t;
cin>>t;
while(t--)
{
ll x,a;
cin>>x>>a;
ll n=a-x;
ll sum=n*(a+1);
sum=sum-n*(n-1)/2;
cout<<sum<<"\n";
}


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

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fo(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

ll t;
cin>>t;
for(int i=0;i<t;i++)
{
ll n,ans=0;
cin>>n;

if(n<3)
ans=0;
else
ans=sqrt(1+n)-1;
cout<<"Case "<<(i+1)<<": "<<ans<<"\n";

}


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

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fo(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

ll t;
cin>>t;
while(t--)
{
double a,b,c,d;
cin>>a>>b>>c>>d;

double sp=(a+b+c+d)/2;
double area=sqrt((sp-a)*(sp-b)*(sp-c)*(sp-d));

cout<<fixed<<setprecision(2)<<(double)area<<"\n";


}


return 0;
}
42 changes: 42 additions & 0 deletions SPOJ_LIST/SPCQ.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include<bits/stdc++.h>

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fo(i,n) for(ll i=0;i<n;i++)
using namespace std;


ll sum(ll n)
{
ll digsum=0;
while(n>0)
{
digsum+=n%10;
n/=10;
}
return digsum;
}

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

ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
while((n%sum(n))!=0)
{
n++;
}
cout<<n<<"\n";
}
return 0;
}
Binary file added SPOJ_LIST/SPOJQUESTIONSLIST.pdf
Binary file not shown.
51 changes: 51 additions & 0 deletions SPOJ_LIST/acpc11b.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include<bits/stdc++.h>

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fo(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

ll t;
cin>>t;
while(t--)
{
ll n,m,diff=0,mini=INT_MAX;
cin>>n;
ll a[n];
fo(i,n)
cin>>a[i];
cin>>m;
ll b[m];
fo(i,m)
cin>>b[i];

sort(a,a+n);
sort(b,b+m);

ll c=0,d=0;
ll res=INT_MAX;

while(c<n && d<m)
{
if(abs(a[c]-b[d])<res)
res=abs(a[c]-b[d]);

if(a[c]<b[d])
c++;
else
d++;
}
cout<<res<<"\n";

}
return 0;
}
Loading

0 comments on commit 3f6bc2c

Please sign in to comment.