View Single Post
  #36  
Old 07-21-2008, 07:47 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
I realized I made an error, but it wouldn't let me edit it... so here is another giant block of code:

PHP Code:
//#CLIENTSIDE
function onWeaponFired() {
  
// Bad match array
  
temp.bad = {
             {
91,50},
             {
60,230},
             {
132,399},
             {
52,293},
             {
22,25},
             {
83,293},
             {
83,82}
             };
  
// Generate students array
  
temp.students = new[400];
  for (
temp.0temp.400temp.i++)
    
temp.students[temp.i] = temp.i;



  
// START of exercise
  
temp.start timevar2;

  
// Shuffle students array
  
temp.temp.students.size();
  for (
temp.0temp.temp.1temp.i++) {
    
temp.temp.random(0,32767) / (32767 / (temp.temp.i) + 1);
    
temp.temp.students[temp.j];
    
temp.students[temp.j] = temp.students[temp.i];
    
temp.students[temp.i] = temp.t;
  }
  
  
// Heapsort the bad match array
  
temp.bad.sortascending();
  
  
temp.pairs = new[50];
  
temp.0;
  while (
temp.50) {
    
temp.pair = {temp.students[temp.x], temp.students[temp.x+1]};

    
// Binary search for the current pair in the bad pairs
    
if (binarysearcharray(temp.badtemp.pair) == -1) {
      
// Add it
      
temp.pairs[temp.i] = temp.pair;
      
temp.students.remove(temp.students[temp.x]);
      
temp.students.remove(temp.students[temp.y]);
      
temp.i++;
      
temp.0;
      
temp.0;
    } else {
      
// Look more
      
if (temp.== temp.students.size()) {
        
temp.x++;
        
temp.0;
      } else {
        
temp.y++;
      }
    }
  }
  
  
  
// END of exercise
  
temp.time timevar2 temp.start;
    
  
player.chat temp.pairs;
  echo (
temp.time);
}

// Modified binary search
function binarysearcharray(temp.atemp.v) {
  
temp.low 0;
  
temp.high temp.a.size()-1;
  while (
temp.low <= temp.high) {
    
temp.mid = (temp.low temp.high) /2;
    if (
temp.a[temp.mid][0] > temp.v[0] || temp.a[temp.mid][0] == temp.v[0] && temp.a[temp.mid][1] > temp.v[1]) 
      
temp.high temp.mid 1;
    else if (
temp.a[temp.mid][0] < temp.v[0] || temp.a[temp.mid][0] == temp.v[0] && temp.a[temp.mid][1] < temp.v[1])
      
temp.low temp.mid +1;
    else
      return 
temp.mid;
  }
  return -
1;

Worst case is actually O(n**2 log n log m), but it uses Randomization and Restriction, so it's considerably fast than the worst case.
Reply With Quote