Skip to content

Commit

Permalink
Merge pull request AASF-IIITM#37 from source-aasf/master
Browse files Browse the repository at this point in the history
merge from source-aasf
  • Loading branch information
haritha1313 authored Oct 8, 2018
2 parents c87e618 + 45ebc19 commit a769be9
Show file tree
Hide file tree
Showing 4 changed files with 249 additions and 0 deletions.
68 changes: 68 additions & 0 deletions c++/MMAXPER.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include <bits/stdc++.h>
using namespace std;

#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define PI acos(-1.0)
#define E exp(1.0)



#define fr(i,a,b) for(int i=a; i<b; i++)
#define fr1(i,a,b) for(int i=a; i<=b; i++)
#define rev(i,a,b) for(int i=b; i>=a; i--)
#define foreach(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define FiLL(A, n, val) for(int i=0; i<n; i++) A[i] = val
#define all(x) x.begin(), x.end()
#define apresent(c,x) (find(all(c),x) != (c).end())
#define T() int tc; cin>>tc; while(tc--)


#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))


ll gcd(ll x, ll y) {return y == 0 ? x : gcd(y, x % y);}
ll power(ll x,ll y){ll temp = 1 ;while(y>0){if(y&1) temp = (temp*x);x*=x;y/=2;}return temp;}
ll DigitSum(ll n) {ll temp = 0; n = abs(n); while(n){temp += (n%10); n/=10; } return temp;}
inline ll modexp(ll a,ll b,ll m) { ll d=1; while(b>0) { if(b&1) d=(d*a)%m; a=(a*a)%m; b=b>>1; } return d; }


#define INF INT_MAX
#define LINF LONG_LONG_MAX
#define MAX 100007
#define MOD 1000000007

int main()
{
_
int n; cin>>n;
int dp[n][2];
memset(dp, 0, sizeof(dp));

int l[n], b[n];
fr(i, 0, n)
cin>>l[i]>>b[i];

fr(i, 0, n)
{
if(i==0)
{
dp[0][0] = b[0];
dp[0][1] = l[0];
}
else{
dp[i][0] = b[i] + max(dp[i-1][0] + abs(l[i] - l[i-1]), dp[i-1][1] + abs(l[i] - b[i-1]));
dp[i][1] = l[i] + max(dp[i-1][0] + abs(b[i] - l[i-1]), dp[i-1][1] + abs(b[i] - b[i-1]));
}
}
cout<<max(dp[n-1][0], dp[n-1][1])<<endl;
return 0;
}

73 changes: 73 additions & 0 deletions c++/RKS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include <bits/stdc++.h>
using namespace std;

#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define PI acos(-1.0)
#define E exp(1.0)



#define fr(i,a,b) for(int i=a; i<b; i++)
#define fr1(i,a,b) for(int i=a; i<=b; i++)
#define rev(i,a,b) for(int i=b; i>=a; i--)
#define foreach(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define FiLL(A, n, val) for(int i=0; i<n; i++) A[i] = val
#define all(x) x.begin(), x.end()
#define apresent(c,x) (find(all(c),x) != (c).end())
#define T() int tc; cin>>tc; while(tc--)


#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))


ll gcd(ll x, ll y) {return y == 0 ? x : gcd(y, x % y);}
ll power(ll x,ll y){ll temp = 1 ;while(y>0){if(y&1) temp = (temp*x);x*=x;y/=2;}return temp;}
ll DigitSum(ll n) {ll temp = 0; n = abs(n); while(n){temp += (n%10); n/=10; } return temp;}
inline ll modexp(ll a,ll b,ll m) { ll d=1; while(b>0) { if(b&1) d=(d*a)%m; a=(a*a)%m; b=b>>1; } return d; }


#define INF INT_MAX
#define LINF LONG_LONG_MAX
#define MAX 100007
#define MOD 1000000007

bool cmp(const pair<int, pair<int, int> >&i, const pair<int, pair<int, int> >&j)
{
if (i.F == j.F)
return i.S.F < j.S.F;
return i.F > j.F;
}

int main()
{
_
int n,c; cin>>n>>c;
vector < pair<int, pair<int, int> > > a(n);
map<int, int> m;
fr(i, 0, n)
{
int s; cin>>s;
if (!m.count(s))
m[s] = i;
a[m[s]].S.F = m[s];
a[m[s]].S.S = s;
a[m[s]].F++;
}

sort(a.begin(), a.end(), cmp);

fr(i, 0, n)
for (int j = 0; j < a[i].F; j++)
cout<<a[i].S.S<<" ";

return 0;
}

71 changes: 71 additions & 0 deletions c++/SCUBADIV.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <bits/stdc++.h>
using namespace std;

#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define PI acos(-1.0)
#define E exp(1.0)



#define fr(i,a,b) for(int i=a; i<b; i++)
#define fr1(i,a,b) for(int i=a; i<=b; i++)
#define rev(i,a,b) for(int i=b; i>=a; i--)
#define foreach(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define FiLL(A, n, val) for(int i=0; i<n; i++) A[i] = val
#define all(x) x.begin(), x.end()
#define apresent(c,x) (find(all(c),x) != (c).end())
#define T() int tc; cin>>tc; while(tc--)


#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))


ll gcd(ll x, ll y) {return y == 0 ? x : gcd(y, x % y);}
ll power(ll x,ll y){ll temp = 1 ;while(y>0){if(y&1) temp = (temp*x);x*=x;y/=2;}return temp;}
ll DigitSum(ll n) {ll temp = 0; n = abs(n); while(n){temp += (n%10); n/=10; } return temp;}
inline ll modexp(ll a,ll b,ll m) { ll d=1; while(b>0) { if(b&1) d=(d*a)%m; a=(a*a)%m; b=b>>1; } return d; }


#define INF INT_MAX
#define LINF LONG_LONG_MAX
#define MAX 100007
#define MOD 1000000007


int dp[2][22][80], o[1000], ni[1000], wt[1000];

int main(){
_
T(){
int t, a;
cin>>t>>a;
int n; cin>>n;

fr(i, 0, n)
cin>>o[i]>>ni[i]>>wt[i];

fr1(i, 0, t)
fr1(j, 0, a)
dp[1][i][j] = 1000000;

dp[1][0][0] = 0;

for(int i = 0,r = 0;i < n;++i,r ^= 1)
fr1(j, 0, t)
fr1(k, 0, a)
dp[r][j][k] = min(dp[r ^ 1][j][k], wt[i] + dp[r ^ 1][max(0, j-o[i])][max(0,k-ni[i])]);

printf("%d\n",dp[(n-1) & 1][t][a]);
}

return 0;
}

37 changes: 37 additions & 0 deletions c++/SUBS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <bits/stdc++.h>
using namespace std;

char ans[500011], x[500011], y[500011];

int main()
{
int t; cin>>t;
while(t--){
cin>>x>>y;
int a = strlen(x);
int b = strlen(y);

int lo = 0, hi = b/a;
int res;
while(lo < hi){
int mid = lo + (hi-lo+1)/2;
int idx = 0;

for(int i=0; i<a; i++)
for(int j=1; j<=mid; j++)
ans[idx++] = x[i];

int sub = 0;
for(int i=0; sub<idx && i<b; i++)
if(ans[sub] == y[i])
sub++;

if(sub == idx)
lo = mid;
else
hi = mid - 1;
}
cout<<lo<<endl;
}
return 0;
}

0 comments on commit a769be9

Please sign in to comment.