Search This Blog

Friday, December 08, 2006

a lot of strcmps...

A lot of strcmps,like:

if (!strcmp (cs,ct)){
...

}

else if (!strcmp (cs,ct)){
...
}
...

else{
...
}



it's too expensive,I think hash will performance better.

Let me try it out...





powered by performancing firefox

Friday, December 01, 2006

a sawfish extension:care-eyes

May be there are many people working just like me,staring at the monitor for a long time.However you are busy,must you take a rest every one or two hours,otherwise,your body will be wore out.
Until now,I have several problems which make me not so good.I can't see clearly those far from me.And after sitting for a while,my neck aches.But often I forgot my discomfort when I am coding or seeing a film or playing a game.So I write this extension to remind me to take a rest.
You can download it here.
Put it to your sawfish's extension directory,and add the following lisp expressions to your sawfish configure file:
(require 'care-eyes)
(eye-care-init 7200 300 nil nil)
here,7200 is the seconds you may work for a longgest time without a rest,i.e. 2 hours,and then you will rest for 5 minutes.
Generally you can ignore the last two arguments,the extension will call xscreensaver to activate the screensaver.Before that,it display a message like this by default:
have a rest,care your eyes:)
You will be able to customize it by set the "resting-message" variable.
That's all,any suggestion or problem,mail to fvwmer[AT]gmail[DOT]com.

Wednesday, November 29, 2006

a problem of CLRS

Water jugs
Suppose that you are given n red and n blue water jugs,all of different shapes and sizes.All red jugs hold different amounts of water,as do the blue ones.Moreover,for every red jug,there is a blue jug that holds the same amount of water,and vice versa.
It is your task to find a grouping of the jugs into pairs of red and blue jugs that hold the same amount of water.To do so,you may perform the following operation:pick a pair of jugs in which one is red and one is blue,fill the red jug with water,and then pour the water int to the blue jug.This operation will tell you whether the red or the blue jug can hold more water,or if they are of the same volume.Assume that such a comparison takes one time unit.Your goal is to find an algorithm that makes a minimum number of comparisons do determine the grouping.Remember that you may not directly compare two red jugs or two blue jugs.

my solution(Ω (nlgn)):for a particular first red jug,each of n blue jugs may has the same amount ,compare this red one with each blue one,and put all the blue ones those hold less amount of water to a set,say,S1,all the blue ones those hold more amount of water to another set,say S2,and make the blue one holds the same amount of water grouped with the red one,then choose a second red jug,compare it with the blue one which holds the same amount of water with the first red jug,if it holds more,then do the same thing with on the first red jug int S2,otherwise in S1,and so on...until all the jugs are grouped