Καλώς ορίσατε στο dotNETZone.gr - Σύνδεση | Εγγραφή | Βοήθεια

Duff Device on Wikipedia

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DuffDeviceFun
{
    class Program
    {
        static void DuffDevice(byte[] src, byte[] dest, int count)
        {

            unsafe
            {
                fixed (byte* fromp = src, top = dest)
                {
                    byte* from = fromp;
                    byte* to = top;
                    int n = (count + 7) / 8;
                    switch (count % 8)
                    {
                        case 0: goto LBL0;
                        case 7: goto LBL7;
                        case 6: goto LBL6;
                        case 5: goto LBL5;
                        case 4: goto LBL4;
                        case 3: goto LBL3;
                        case 2: goto LBL2;
                        case 1: goto LBL1;
                    }
                LBL0: *to++ = *from++;
                LBL7: *to++ = *from++;
                LBL6: *to++ = *from++;
                LBL5: *to++ = *from++;
                LBL4: *to++ = *from++;
                LBL3: *to++ = *from++;
                LBL2: *to++ = *from++;
                LBL1: *to++ = *from++;
                    if (--n > 0)
                        goto LBL0;
                }
            }
        }
        static void Main(string[] args)
        {
            string msg = "Demo Message!";
            var len = msg.Length * sizeof(char);
            byte[] from = new byte[len];
            Buffer.BlockCopy(msg.ToCharArray(), 0, from, 0, len);
            byte[] to = new byte[from.Length * sizeof(char)];
            DuffDevice(from, to, len);
            char[] res = new char[to.Length / sizeof(char)];
            Buffer.BlockCopy(to, 0, res, 0, to.Length );
            Console.WriteLine(res);
            Console.ReadKey();
        }
    }
}
0 σχόλια
Δημοσίευση στην κατηγορία: , , ,

Link to pastebin

object TicTacToeTomek {
    def solve(arr: List[List[Char]]) : String = {
        def checkWin(a: List[Char]) : String = {
            val o = a.filter(c=>c=='O').length
            val x = a.filter(c=>c=='X').length
            val t = a.filter(c=>c=='T').length
            if(o+t==4) return "O won"
            else if(x+t==4) return "X won"
            else return null
        }
        for(i<-0.to(3)) {
            val h = arr(i)
            val hres = checkWin(h)
            if(hres!=null) return hres
            val v = List(arr(0)(i),arr(1)(i),arr(2)(i),arr(3)(i))
            val vres = checkWin(v)
            if(vres!=null) return vres
        }
        val d1 =  List(arr(0)(0),arr(1)(1),arr(2)(2),arr(3)(3))
        val d1res = checkWin(d1)
        if(d1res!=null) return d1res
        val d2 =   List    (arr(0)(3),arr(1)(2),arr(2)(1),arr(3)(0))
        val d2res = checkWin(d2)
        if(d2res!=null) return d2res
        arr.foreach(a=>a.foreach(c=>if(c=='.') return "Game has not completed"))
        return "Draw"
    }
    
    def main(args: Array[String]):Unit = {
        val T = readLine().toInt
        for(i<-1.to(T)) {
            val arr = List[List[Char]](readLine().toList,readLine().toList,readLine().toList,readLine().toList)
            val empt = readLine()
            println("Case #"+i+": " + solve(arr))
        }
    }
}

0 σχόλια
Δημοσίευση στην κατηγορία: , , , , , , ,

Below is my implementation of a Dynamic Service Locator

ServiceLocator.scala

import scala.reflect.runtime.{universe => ru}
trait ServiceLocator {
  def getService[T](implicit t: ru.TypeTag[T]) : T
  def registerService[T](obj: T)(implicit t: ru.TypeTag[T]) : Unit
}

ServiceLocatorImpl.scala

import scala.reflect.runtime.{ universe => ru }
import scala.reflect.runtime.universe.Type

class ServiceLocatorImpl extends ServiceLocator {
  val rep = new scala.collection.mutable.HashMap[reflect.runtime.universe.Type, Any]()

  private def internalServiceSearch(t: Type): Option[Any] = {
    val tpe = t
    for {
      s <- rep.keys
      if (s <:< tpe || s =:= tpe)
    } return Some(rep(s))
    None
  }
  def getService[T](implicit t: ru.TypeTag[T]): T = {
    val res = internalServiceSearch(t.tpe)
    res match{
      case None => throw new Exception("Service not found")
      case _ => res.get.asInstanceOf[T]
    }
  }
  def registerService[T](obj: T)(implicit t: ru.TypeTag[T]): Unit = {
    if (internalServiceSearch((t).tpe) == None) rep.put(t.tpe, obj.asInstanceOf[Any])
  }
}

0 σχόλια
Δημοσίευση στην κατηγορία: ,

Υπάρχουν περιπτώσεις που θέλουμε να καλέσουμε μια βιβλιοθήκη μας που έχουμε γράψει σε C# απο την VB6 για να έχουμε τα καλούδια του .Net, κυρίως όταν έχουμε να κάνουμε με συστήματα γραμμένα σε COM και ο μόνος τρόπος να τα επεκτείνουμε είναι να κάνουμε addins σε VB.

Αυτα που χρειάζεται να κάνουμε είναι τα εξής:

1) Οι μέθοδοι, μεταβλητές κλπ που θέλουμε να καλούμε απο την VB πρέπει να είναι δηλωμένα σε ένα Interface

2) Το interface να υλοποιείται στην κλάση explicit πχ

[Guid("DA243ABC-6205-4511-81FD-60F07057ACD7")]
    public interface IClass1
    {
         string SampleField { get; set; }

         void SampleMethod();

         void SampleMethod2(string Param1);

         string SampleFunction();

         string SampleFunction2(string Param1);
    }
    [Guid("571583E7-B26C-4842-B5AD-952820831A70")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("MyClassLib.Class1")]
    public class Class1 : IClass1
    {
        private string _SampleField;
        string IClass1.SampleField
        {
            get{
                return _SampleField;
            }
            set { _SampleField = value; }
        }

        void IClass1.SampleMethod()
        {
            System.Windows.Forms.MessageBox.Show("My Sample Method");
        }

         void IClass1.SampleMethod2(string Param1)
        {
            System.Windows.Forms.MessageBox.Show("My Sample Method " + Param1);
        }

         string IClass1.SampleFunction()
        {
            return "Sample Function";
        }

         string IClass1.SampleFunction2(string Param1)
        {
            return Param1;
        }
    }

 

3) να προσθέσετε τα attributes Guid, ClassInterface

4) να βάλετε στις ρυθμίσεις του Project, στο Assembly Informations, check στο COM Visible

5) να δημιουργήσετε ένα αρχείο snk για να κάνετε Sign το assembly για να μπορεί να γίνει register sto GAC.

sn –k mykey.snk

6) στις ρυθμίσεις του Project , στο Signing, κάντε check το Sign this assembly και επιλέξτε το αρχείο που δημιουργήσατε.

7) κάντε compile και μετά τρέξτε το

gacutil /i MyClassLib.dll /f

tlbexp MyClassLib.dll

regasm MyClassLib.dll /tlb:MyClassLib.tlb

 

ή διαφορετικά στις ρυθμίσεις του Project, στο Build κάντε check το Register for COM interop. (Χρειάζεται να τρέξετε το Visual Studio ως administrator)

 

Προσοχή σε 64 bit λειτουργικά ότι πρέπει στις ρυθμίσεις στο Build στο Platform Target να βάλετε το x86.

 

Μετά απλά προσθέτετε στα References στη VB6 τη βιβλιοθήκη σας ή δυναμικά την καλείτε.

Share/Bookmark a2a_linkname="C# και VB6 μαζί;";a2a_linkurl="http://www.studentguru.gr/blogs/ikaragkiozoglou/archive/2011/08/08/c-vb6.aspx";

 I post my implementation of the Edmonds-Karp Algorithm. link to pastebin http://pastebin.com/HrxTvN4m

  1. #include <iostream>
  2. #include <climits>
  3. #define MAXN 100
  4. using namespace std;
  5. typedef struct node_t node_t;
  6. typedef struct edge_t edge_t;
  7. struct edge_t {
  8.     int cap, ni,i;
  9. };
  10. struct node_t{
  11.     int i;
  12.     edge_t edges[MAXN];
  13. };
  14. node_t nodes[MAXN];
  15. int nedges[MAXN]={0};
  16. int edmondskarp(int source, int sink, int n){
  17.     int max = 0;
  18.     while(true){
  19.         int q[MAXN]={0}, mins[MAXN]={INT_MAX}, h=0,t=0,c,i,j,min=INT_MAX;
  20.         edge_t *pre[MAXN]={NULL}, *u;
  21.         q[t++]=source;
  22.         while(t>h && pre[sink]==NULL){
  23.             c = q[h++];
  24.             for(i=0;i<n;i++) {
  25.                 if(nodes[c].edges[i].cap>0 && pre[nodes[c].edges[i].ni]==NULL){
  26.                     q[t++]=nodes[c].edges[i].ni;
  27.                     pre[nodes[c].edges[i].ni]=&nodes[c].edges[i];
  28.                     if(mins[c]>nodes[c].edges[i].cap) mins[nodes[c].edges[i].ni]=nodes[c].edges[i].cap;
  29.                     else mins[nodes[c].edges[i].ni]=mins[c];
  30.                 }
  31.             }
  32.         }
  33.         if(pre[sink]==NULL) break;
  34.         for(u=pre[sink];pre[(*u).i]!=NULL;u=pre[(*u).i]){
  35.             (*u).cap-=mins[sink];
  36.         }
  37.         max+=mins[sink];
  38.     }
  39.     return max;
  40. }
  41.  
  42. int main(){
  43.     int n, m, i, k, j, c,maxflow;
  44.     cin >> n >> m;
  45.     for(i=0;i<m;i++) {
  46.         cin >> k >> j >> c;
  47.         nodes[k].i=k;
  48.         nodes[k].edges[nedges[k]].i=k;
  49.         nodes[k].edges[nedges[k]].cap =c;
  50.         nodes[k].edges[nedges[k]].ni=j;
  51.         nedges[k]++;
  52.     }
  53.     maxflow=edmondskarp(0,n-1,n);
  54.     cout << maxflow << endl;
  55.     cin >> i;
  56.     return 0;
  57. }
Share/Bookmark a2a_linkname="Maximum Flow - Edmonds-Karp Algorithm";a2a_linkurl="http://www.studentguru.gr/blogs/ikaragkiozoglou/archive/2011/03/08/maximum-flow-edmonds-karp-algorithm.aspx";
0 σχόλια
Δημοσίευση στην κατηγορία: , , , , , , , ,

Σας παραθέτω μια προσέγγιση στη λύση του προβλήματος "christmas" του hellenico.gr

Ο αλγόριθμος που χρησιμοποίησα είναι του Kruskal. Η Δομή δεδομένων μου για Disjoint Sets είναι Linked List.

Για το δεύτερο MST κάνω:

   Για κάθε edge που ανήκει στο πρώτο MST

         την αφαιρώ απο τη λύση και ψαναφτιάχνω το linked list χωρις αυτήν.

         τρέχω τον Kruskal απο το σημείο που είχε σταματήσει ο πρώτος αφαιρόντας το κόστος της συγκεκριμένς ακμής

         αν το αποτέλεσμα είναι το επόμενο μεγαλύτερο του πρώτου ειναι και το σωστό

(Sorry για τα ορθογραφικά.. δεν είχα το χρόνο για να τα τσεκάρω)

 Οποιοδήποτε σχόλιο και διόρθωση είναι καλοδεχούμενα!!!

Κώδικας => http://pastebin.com/4qzCLFu1.

Το Πρόβλημα:

Όσον αφορά στην μορφή της εισόδου, στην πρώτη γραμμή θα δίνεται το πλήθος N των
κορυφών / διασταυρώσεων και το πλήθος M των ακμών / δρόμων. Σε καθεμία από τις
υπόλοιπες M γραμμές θα δίνονται τα χαρακτηριστικά μιας ακμής e: πρώτα δύο
θετικοί ακέραιοι που αντιστοιχούν στα δύο άκρα της ακμής, και έπειτα ένας
θετικός ακέραιος που αντιστοιχεί στο μήκος της d(e).

 3<=N<=2000
3<=M<=10^5
1<=d(e)<=10^9

Bonus:
Δύο
επιπλέον παραδείγματα αξιολόγησης με Ν = 50000.

Παράδειγμα εισόδου
(αρχείο "christmas.in")

3 3
2 1 67
3 1 46
3 2
75


Παράδειγμα εξόδου (αρχείο "christmas.out")

113
121

Παράδειγμα εισόδου 2 (αρχείο "christmas.in")

5 9
2 1 29
3 2 52
4 1 20
5 3 45
2 5 42
2 4 19
1 5 5
5 4 26
4 3
76


Παράδειγμα εξόδου 2 (αρχείο "christmas.out")

89
95

Παράδειγμα εισόδου 3 (αρχείο "christmas.in")

6 9
1 2 50
1 3 80
2 3 60
2 4 20
3 5 40
2 5 30
4 5 10
4 6 10
5 6
50

Παράδειγμα εξόδου 3 (αρχείο "christmas.out")

130 140

Share/Bookmark a2a_linkname="First and Second Minimum Spanning Tree,Kruskal in C";a2a_linkurl="http://www.studentguru.gr/blogs/ikaragkiozoglou/archive/2011/02/24/first-and-second-minimum-spanning-tree-kruskal-in-c.aspx";
0 σχόλια
Δημοσίευση στην κατηγορία: , , , , , , ,
  Προαπαιτούμενα : .Net Framework 3.5, Visual Studio 2008, Windows API Code Pack   Αφού κατεβάσουμε το Windows API Code Pack , κάνουμε ένα νέο Project στο Visual Studio και προσθέτουμε στα reference τα Microsoft . WindowsAPICodePack . dll και Microsoft . WindowsAPICodePack . Shell . dll . Taskbar è Progress (Value, State, Overlay Icon) è Jump List (Tasks, Custom Categories)

Διαβάστε περισσότερα »

Αν ψάχνετε και εσείς πολλές φορές στο Google για να βρείτε μια απάντηση η μια βοήθεια θα έχετε καταλήξει στο CodeProject. Μάλλον δεν θα ήμασταν και οι μόνοι και έτσι το CodeProject σκέφτηκε να κάνουμε τα search μας στην βάση του μέσα από Το VS. Δείτε εδώ . Κάντε download εδώ . Μοιραστείτε τη δημοσίευση: email-it! | Share on Facebook | ForaCamp.gr! | DigMe! | BobIt! | Buzz! | CheckIt!

Διαβάστε περισσότερα »

0 σχόλια
Δημοσίευση στην κατηγορία: , , ,
Έφτιαξα ένα Tool για έναν φίλο που μου ζήτησε γιατί είχε ξεχάσει μια φίλη τον κωδικό του MSN της. Σαν καλό φιλαράκι( αφού πληρώθηκα σε φραπέ όπως πάντα.χα0χ0α) έκανα το εργαλείο που προσπαθεί με wordlist να σπάσει τον κωδικό. Για να κάνω Generate Word List χρησιμοποιώ το Professional Password Generator 2007. ( Όποιος ψάχνετε βρίσκει..!!!). PS. Για να κάνω το connection με το MSN βρήκα

Διαβάστε περισσότερα »

0 σχόλια
Δημοσίευση στην κατηγορία: , ,
Αν θέλετε η ομάδα σας να γράφει στο ίδιο project ταυτόχρονα θα χρειαστείτε κάποιο source control server και client για το visual studio. Υπάρχουν από την πλευρά της microsoft 2 source control εργαλεία το Visual Source Safe 2005 και το Team Foundation System. Το Visual Source Safe δεν επιτρέπει συνδέσεις μέσο internet εκτός αν συνδέονται μέσο VPN. Το TFS είναι ένα εργαλείο που δεν είναι

Διαβάστε περισσότερα »

0 σχόλια
Δημοσίευση στην κατηγορία: , , , , , , ,
Μερικά Link που μας κάνουν τη ζωή πιο εύκολη!!! http://www.free-css.com/ <= Έχει CSS αλλά και ξεχωριστά CSS μόνο για μενού!! http://css4free.com/ <= Ψάξτε το καλά έχει πολύ ωραία templates http://www.csswizard.net/ <= Εργαλείο για την δημιουργία CSS και templates με wizard :P http://www.cssmenubuilder.com/home <= Εργαλείο για την δημιουργία CSS μενού :D:D http://www.cssbasics.com/

Διαβάστε περισσότερα »

0 σχόλια
Δημοσίευση στην κατηγορία: , , , , , , , , , ,
Ψαχνόμουν χθες λίγο το βραδάκι και έπεσα πάνω σε ένα Plugin για τον IE7. "IE7Pro is a must have add-on for Internet Explorer, which includes a lot of features and tweaks to make your IE friendlier, more useful, secure and customizable. IE7Pro includes Tabbed Browsing Management, Spell Check, Inline Search, Super Drag Drop, Crash Recovery, Proxy Switcher, Mouse Gesture, Tab History

Διαβάστε περισσότερα »

0 σχόλια
Δημοσίευση στην κατηγορία: , , , ,