May 21, 2012

2012 ACM ICPC Final



Check out the problems


And the final results

Apr 3, 2012

How to program nodes movement using FOR loop in NS2


In fact, we know how to set the nodes` movement in NS2, it could be < $ns at TIME "$NODE1 setdest $val(X1) $val(Y1) SPEED" >. However, for some scenario, it may contain a large number of nodes` movement and simulation time could be one or several hours. It is impossible to program in this static way.

So we consider using a FOR loop. Here is an example where a node is moving up and down. The simulation time can be any value and we just need five lines program. The program is like the following,


for {set i 1} {$i < ($val(stop))} {set i [expr {$i + 10}]} {


$ns at $i "$node_(1) setdest $val(X1) $val(Y1) NodeSpeed"


set i [expr {$i + 10}]


$ns at $i "$node_(1) setdest $val(X2) $val(Y2) NodeSpeed"


}

Mar 7, 2012

Extend hard disc space for VMware in Mac OS


It is a common problem that the system space in the virtual machine is not enough we allocated before. We may need to extend its size after the system installation. So here is the way.

1) Open VMware Fusion and choose your virtual machine from the "Virtual Machine Library" list. Choose "Settings" from the "Virtual Machine" menu and select "Hard Disks."

2) Adjust the size of your hard disk by using the slider. Click "Apply" when finished.

If you have a Windows 7 or Vista virtual machine,

3) Start your virtual machine and log in as an administrator. Click "Start" and select "Control Panel." Click "System and Security" and then "Administrative Tools." Double-click the "Computer Management" option and click "Disk Management" on the left pane of the window that appears. Right-click on your virtual machine's volume and choose "Extend Volume." Click "Next" twice and then "Finish.

Feb 2, 2012

Check the number of words in LATEX


We use a perl program to count the LATEX article words.



BEGIN {

%cutlist = (

'begin' => 1,

'end' => 1,

'usepackage' => 1,

'addtolength' => 1,

'documentclass' => 1,

'author' => 1,

'title' => 1,

'chapter' => 1,

'bibliography' => 1,

'bibliographystyle' => 1,

'section' => 1,

'subsection' => 1,

'subsubsection' => 1,

'thanks' => 1,

'pagestyle' => 1,

);

my $line = '';

my $cumline = '';

my $depth = 0;

my $words = 0;

my $fnwords = 0;

my $i = 0;

my @tags = ();

my $thistag = '';

}


$line = $_;



# Regularize line endings

$line =~ s/\r/\n/g;



# Remove comments

$line =~ s/(?


# Count curly braces

while($line =~ /\{/g){$depth++}

while($line =~ /\}/g){$depth--}






$cumline .= $line;


if ($depth == 0) {


while($cumline =~ s/(\\\w+)?\s*\{([^\{\}]*)\}/<"$i"<$2>"$i">/s){push @tags, $1; $i++;}


$i = 0;

while($#tags >= 0){

$thistag = shift @tags;

$thistag =~ s/\\//;


if ($thistag eq 'footnote') {

# Footnotes are counted separately.

$cumline =~ s/<"$i"<(.*)>"$i">//s;

$line = $1;

while($line =~ /\b\w+\b/g){$fnwords++};


} elsif (defined($cutlist{$thistag})) {


# The arguments of these tags are removed.

$cumline =~ s/<"$i"<.*>"$i">//s;


} else {


# The arguments of other tags are left in.

$cumline =~ s/<"$i"<(.*)>"$i">/$1/s;


};


$i++;

}



$cumline =~ s/\\\w+//g;




# Count the remaining words in the present bit of text.

while($cumline =~ /\b\w+\b/g){$words++}

$cumline = '';

$i = 0;

}



END{

print "\n$words words in the main text\n$fnwords in the footnotes\n";

print ($words+$fnwords);

print " total\n\n";

}



Store this program in a XXX.pl file, and run it in command line.


>perl XXX.pl foo.tex