25
Jul
11

Hablu


My first experience of problem setting. It feels good when you see people think about your problem and come up with better solutions than yours :P
This problem is about math and primes. The link is this.

24
Mar
11

People That Come Into Your Life.


Sometimes people come into your life and you know right away that they were meant to be there, to serve some sort of purpose, teach you a lesson, or to help you figure out who you are or who you want to become. You never know who these people may be (possibly your roommate, neighbour, co-worker, longest friend, lover, or even a complete stranger) but when you lock eyes with them, you know at that very moment that they will affect your life in some profound way.

Some people come into our lives and quickly go.
Some people move our souls to dance.
They awaken us to new understanding with the passing whisper of their wisdom.
Some people make the sky more beautiful to gaze upon.
They stay in our lives for awhile, leave footprints in our hearts,
and We are never, ever the same.

And sometimes things happen to you that may seem horrible, painful, and unfair at first, but in reflection you find that without overcoming those obstacles you would have never realised your potential, strength, willpower, or heart. Everything happens for a reason, nothing happens by chance or by means of luck. Illness, injury, love, lost moments of true greatness, and sheer stupidity all occur to test the limits of your soul. Without these small tests, whatever they may be, life would be like a smoothly paved, straight flat road to nowhere. It would be safe and comfortable, but dull and utterly pointless. The people you meet who affect your life, and the success and downfalls you experience help to create who you become.

Even the bad experiences can be learned from. In fact, they are probably the most poignant and important ones.

If someone hurts you, betrays you, or breaks your heart, forgive them, for they have helped you learn about trust and the importance of being cautious when you open your heart. If someone loves you, love them back unconditionally, not only because they love you, but because in a way, they are teaching you to love and how to open your heart and eyes to things.

Make every day count!! Appreciate every moment and take from those moments everything that you possibly can for you may never be able to experience it again. Talk to people that you have never talked to before, and actually listen. Let yourself fall in love, break free, and set your sights high. Hold your head up because you have every right to. Tell yourself you are a great individual and believe in yourself, for if you don’t believe in yourself; it will be hard for others to believe in you.

You can make of your life anything you wish. Create your own life then go out and live it with absolutely no regrets.

03
Mar
11

UVa Easy Problem List


UVa(University of Valladolid) has one of the best online judges to start online problem solving. Here is a list of some easy problems from UVa for newbies.

100, 119, 133, 136, 146, 272, 401, 409, 412, 440, 444, 446, 458, 468, 476, 488, 489, 490, 492, 494, 498, 499, 541, 575, 579, 583, 729, 900, 913, 10035, 10038, 10055, 10071, 10082, 10110, 10222, 10235, 10327, 10346, 10370, 10424, 10469, 10591, 10696, 10699, 10789, 10812, 10922, 10924, 10929, 10931, 10970, 11152, 11172, 11185, 11192, 11219, 11233, 11462, 11530, 11727, 11764, 11799, 11804, 11805, 11827, 11854, 11875, 11900, 11917

13
Dec
10

Kruskal’s Algorithm


Kruskal’s algorithm is the best and probably fastest option if you’re urging to form a subgraph of a graph connecting all nodes. Some implementations are shown.

Minimum Spanning Tree
To form an MST(Minimum Spanning Tree) follow this procedure,

1. Begin with a connected graph G.
2. E is the set of all edges of different weights, from G.
3. Sort edges of E in the ascending order of their weights.
4. Go through each member(edge) of E and see if the nodes of that edge is already connected or not.
5. If they aren’t connected, connect them and include that member of E(edge) int MST.
6. Continue this process untill you’ve got n-1 edges(in case of n nodes).

An implementation in C++ using Disjoint Set data structure, is shown

#include <cstdio>
#include <algorithm>
#define MAX_node 100000
using namespace std;

struct edg{
	int a,b,w;
	bool operator < (const edg &b) const{
		return w<b.w;
	}
}E[MAX_node+1];

int Prev[MAX_node+1];
int parent(int a){
	if(a==Prev[a]) return a;
	return Prev[a]=parent(Prev[a]);
}

int main(){
	int node,edge;
	while(scanf("%d%d",&node,&edge)){
		
		int TOTAL=0;
			
		for(int i=1;i<=node;i++) Prev[i]=i;//*
		for(int i=0;i<edge;i++) scanf("%d%d%d",&E[i].a,&E[i].b,&E[i].w);//**
		
		sort(E,E+edge);//***
		
		for(int i=0; i<edge; i++ ){
			int u=parent(E[i].a);//****
			int v=parent(E[i].b);
			
			if(u!=v){
				TOTAL+=E[i].w;
				Prev[u]=v;//*****
			}
		}
		
		printf("Total Cost of MST %d\n",TOTAL);
	}
	return 0;
}

/*
 * Making each node it's own parent
 ** Input edges in the format "node1 node2 weight"
 *** Sorting them in the ascending order of weight
 **** Find the current parent of a and b
 ***** If the nodes of that edge is not connected yet, Connect them.
 */

if you don’t know Maximum possible number of nodes, then just use a vector(which is a bit slower) of type ‘edg’.

Related Problems
MST(spoj)
Dark Roads(UVa)
Audiophobia(UVa)
Connect the Campus(UVa)
Highways(UVa)



Maximum Spanning Tree
To get a maximum spanning tree, the procedure is almost same. The only difference is that, you got to sort members of E in the descending order of their weights.

Related Problems
Heavy Cargo(UVa)



Second Best Minimum Spanning Tree
There may be some other better procedure to find the second best MST, but this is the one I’ve used.
1. First form an MST of graph G, and mark the edges which formes the MST.
2. Then for each member edge of the MST, Form another MST without using that particular member.
3. Thus, u need to form n-1 (in case of n nodes) ‘another’ MSTs and consider the minimun among them.

Related Problems
Is There A Second Way Left ?(UVa)
ACM contest and Blackout(UVa)

27
Nov
10

Happiness is the journey, not a destination


Happiness is now .. where you are, in this moment .. doing what you are doing without worrying about the outcome .. or trying to get away from something.

Are you trying to convince yourself that life will be better after you complete some project .. or that doing this course will make you happy or give you a purpose? Will getting this therapy make you happy?

Patterns have a way of repeating themselves .. and life is a series of patterns!

Living in the moment is not waiting until after you get married, or have one baby .. then another.

One day you’ll be frustrated that the kids aren’t old enough (but you’ll be more content when they are). Then there will be the teenage years to deal with .. do you remember yours? Maybe you’ll find happiness when they are out of that stage.

We tell ourselves that our life will be complete when our partner gets his or her act together, when we get a nicer car, are able to go on a nice vacation, when we retire.

The truth is, there’s no better time to be happy than right now. If not now, when? Your life will always be filled with challenges and changes.

Who promised you that, sometime in the future, life will begin to begin – real life. There always seems to be some obstacle in the way, something to be gotten through first, some unfinished business, time still to be served, a debt to be paid.

Life embraces these obstacles, envelopes them, flows around them, under them and through them.

There is no way to happiness.

Happiness is the experience of living Life, fully in this moment and exploring all that this moment has to offer.

So, treasure every moment that you have. And treasure it more because you shared it with someone special, special enough to spend your time… you .. your Self ..

(and, remember that you (either consciously or unconsciously) attracted this moment to you for your highest evolution and growth)

Happiness is a journey – not a destination. Each journey starts with a single step .. and continues one step at a time .

Are you waiting until you finish school, until you go back to school, until you lose ten pounds, until you gain ten pounds, until you have kids, until your kids leave the house, until you start work, until you retire, until you get married, until you get divorced, until Friday night, until Sunday morning, until you get a new car or home, until your car or home is paid off, until spring, until summer, until fall, until winter, until you are off welfare, until the first or fifteenth, until your song comes on, until you’ve got drunk, until you’ve sobered up, until you die, until you are born again …

You can experience happiness when you decide that, in this moment, there is no better time to be happy ..

and that means unconditionally accepting your self in this moment, just the way you are .. only then can this moment give way to a brand new moment and a brand new experience .. of happiness

Happiness is the journey, not a destination.

- Souza




Hit Counter

  • 14,282 hits

To receive notifications of new posts on Encrypted Illusions by email, type your email address in the blank space below and then hit the tab to sign up

Join 4 other followers

Post Categories

Blog Map


Home




Author




Coding




Thoughts


Follow

Get every new post delivered to your Inbox.