diff --git a/special binary string.cpp b/special binary string.cpp new file mode 100644 index 0000000..1a9e640 --- /dev/null +++ b/special binary string.cpp @@ -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 res; + for(int j=0;j()); + + string r = ""; + for(auto s:res){ + r+=s; + } + return r; + } diff --git a/wormholes.cpp b/wormholes.cpp new file mode 100644 index 0000000..23bc4b3 --- /dev/null +++ b/wormholes.cpp @@ -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 +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>t; + while(t--) { + + cin>>n; + int sx,sy,dx,dy; + cin>>sx>>sy>>dx>>dy; + + for(int i=0;i>w[i][j]; + } + } + ans=999999; + cal(sx,sy,dx,dy,0); + cout<<"#"<