Skip to content
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
41 changes: 41 additions & 0 deletions special binary string.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*

CITRIX IIT Guwahti 2019

Special binary strings are binary strings with the following two properties:

The number of 0's is equal to the number of 1's.
Every prefix of the binary string has at least as many 1's as 0's.
Given a special string S, a move consists of choosing two consecutive, non-empty,
special substrings of S, and swapping them. (Two strings are consecutive if the last character
of the first string is exactly one index before the first character of the second string.)

At the end of any number of moves, what is the lexicographically largest resulting string possible?

Solution:
Recursively try to find the lexicographically largest strings and sort them using a comparator function.

*/

string makeLargestSpecial(string S) {
int i=0, count=0;
vector<string> res;
for(int j=0;j<S.length();j++){
if(S[j]=='1')
count++;
else
count--;
if(count==0){
res.push_back('1' + makeLargestSpecial(S.substr(i+1,j-i-1)) +'0');
i = j+1;
}

}
sort(res.begin(),res.end(),greater<string>());

string r = "";
for(auto s:res){
r+=s;
}
return r;
}
61 changes: 61 additions & 0 deletions wormholes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Samsung Bangalore NIT Agartala 2019

There is one spaceship. X and Y co-odinate of source of spaceship and destination spaceship is given.
There are N number of warmholes; each warmhole has 5 values.
First 2 values are starting co-ordinate of warmhole and after that value no. 3 and 4 represents ending
co-ordinate of warmhole and last 5th value is represents cost to pass through this warmhole.
Now these warmholes are bi-directional. Now the to go from (x1,y1) to (x2,y2) is abs(x1-x2)+abs(y1-y2).
The main problem here is to find minimum distance to reach spaceship from source to destination
co-ordinate using any number of warm-hole.
It is ok if you wont use any warmhole.
*/

#include<iostream>
using namespace std;

int ans,mask[10],w[10][5],n;

int distance(int sx,int sy,int dx,int dy) {
int xd=(sx>dx)?(sx-dx):(dx-sx);
int yd=(sy>dy)?(sy-dy):(dy-sy);
return (xd+yd);
}

void cal(int sx,int sy,int dx,int dy,int dis) {

ans=min(ans,distance(sx,sy,dx,dy)+dis);

for(int i=0;i<n;i++) {
if(mask[i]==0) {
mask[i]=1;
int temp=distance(sx,sy,w[i][0],w[i][1])+dis+w[i][4];
cal(w[i][2],w[i][3],dx,dy,temp);
temp=distance(sx,sy,w[i][2],w[i][3])+dis+w[i][4];
cal(w[i][0],w[i][1],dx,dy,temp);
mask[i]=0;
}
}
}
int main() {
int t,index=1;
cin>>t;
while(t--) {

cin>>n;
int sx,sy,dx,dy;
cin>>sx>>sy>>dx>>dy;

for(int i=0;i<n;i++) {
mask[i]=0;
for(int j=0;j<5;j++) {
cin>>w[i][j];
}
}
ans=999999;
cal(sx,sy,dx,dy,0);
cout<<"#"<<index<<" "<<ans<<endl;
index++;
}
return 0;
}