Posts

Showing posts from April, 2016

LOJ: 1299 - Fantasy Cricket

LOJ: 1299 - Fantasy Cricket IDEA: The idea is explained by commenting out on code below. ///============================================================================/// /// /// /// IT'S ME /// /// BISHAL GAUTAM /// /// CSE,JAHANGIRNAGAR UNIVERSITY,DHAKA /// /// "Follow Excellence..Success will chase U" /// /// /// ///============================================================================/// #include<bits/stdc++.h> #define PI acos(-1.0) #define X first #define Y second #define mpp make_pair #define nl printf("\n") #define SZ(x) (int)(x.size()) #define pb(x) push_back(x) #define pii pair<int,int>

LOJ: 1325 - Distributing Chocolates (Shank-Baby-Step-Giant-step-algo)

LOJ: 1325 - Distributing Chocolates IDEA:           Let us consider an equation:  (a^b)%m= n.   The problem has given you the value of a , m and n , You have to calculate the smallest value of  b that satisfies above relation. Since, b can be also written as PHI(m) , so value of b lies within m . Now, we can formulate that: b=p*y-q . So, we may got:  a^(p*y) = n*a^q  (mod-m is applied both sides) Let us precalculate and store values of RHS on map. Now, we may pick and fixed value for p as a constant let sqrt(m) then another variable y will loop maximum sqrt(m) , then we may compare LHS with RHS by extracting value of RHS from map. ///============================================================================/// /// /// /// IT'S ME /// /// BISHAL GAUTAM /// ///

SPOJ: WORDS1 - Play on Words (Eular Path)

Image
SPOJ: WORDS1 - Play on Words (Eular Path) Idea:   For a given list of words simply checks whether we can form a chain of words joining  end of word with begining of word. As we know that for a graph to have an eularian path, there  must be either no odd degree vertices or exactly two vertices having odd degree,in this case  one verices must have one extra outgoing degree and another must have one extra incoming  degree. (Note: as a whole graph should be connected, check this by  union find.)  ///============================================================================/// /// /// /// IT'S ME /// /// BISHAL GAUTAM /// /// CSE,JAHANGIRNAGAR UNIVERSITY,DHAKA /// /// "Follow Excellence..Success will chase U"

UVA: 10525 - New to Bangladesh?

UVA: 10525 - New to Bangladesh? Idea: Simple Dijakstra. Main problem is to understand the problem. The problem has given the road map graph each edge has distance and time penalty. The problem is asking for the closest possible time to go from start to end, if it takes same time for two roads then choose the smallest distance one. ///============================================================================/// /// /// /// IT'S ME /// /// BISHAL GAUTAM /// /// CSE,JAHANGIRNAGAR UNIVERSITY,DHAKA /// /// "Follow Excellence..Success will chase U" /// /// /// ///=================================================================

Codeforces 267Div2D : Fedor and Essay (SCC)

Codeforces 267Div2D : Fedor and Essay (SCC) IDEA: Problem has given different transformation relations( Direct ) between different words, We have to transform a given list of words using that transformation dictionery so that finally we got less amount of words containing letter "r", in the same "r" , we have to minimize length of final eassy wors. For this obviously, if we represents relations between dictionery words , we got a directed graph. Then for each word in a dictionery we can obviously know the best optimal word which has less "r" is a word which is reachable using directed edge in that graph. The problem with above graph is that it may end in a loop.So, at first, we should transform the graph to DAG after finding SCC. We also calculate the best word for each SCC. After that we do dynamic programming from each node of DAG to get optimal result. ///============================================================================/// ///

UVA: 10731 - Test (SCC)

UVA: 10731 - Test ///============================================================================/// /// /// /// IT'S ME /// /// BISHAL GAUTAM /// /// CSE,JAHANGIRNAGAR UNIVERSITY,DHAKA /// /// "Follow Excellence..Success will chase U" /// /// /// ///============================================================================/// #include<bits/stdc++.h> #define PI acos(-1.0) #define X first #define Y second #define mpp make_pair #define nl printf("\n") #define SZ(x) (int)(x.size()) #define pb(x) push_back(x) #define pii pair<int,int> #define pll pair<ll,ll> #define pdd pair<double,double> ///==S