Results 1 to 14 of 14

Thread: Java

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User bombov's Avatar
    Join Date: Jan:2007
    Location:
    Posts: 260

    Java

    :
    if (A[i][k] && !used[k])
    ?

  2. #2
    Registered User
    Join Date: Apr:2004
    Location: EU
    Posts: 141
    :

    if (A[i][k] && !used[k])

  3. #3
    philosophus duratea icaci's Avatar
    Join Date: Oct:2006
    Location: Aachen
    Posts: 2,698
    Quote Originally Posted by zstoev View Post
    :

    if (A[i][k] && !used[k])
    , A boolean. :

    if (A[i][k] != 0 && !used[k])
    Internet - it doesn't make you stupid, it just makes your stupidity more accessible to others

  4. #4
    Registered User
    Join Date: Apr:2004
    Location: EU
    Posts: 141
    icaci, ! A boolean.
    used.

  5. #5
    Registered User bombov's Avatar
    Join Date: Jan:2007
    Location:
    Posts: 260
    ( =++ ; )

    Code:
    #include <stdio.h>
    
    /*      */
    #define MAXN 200
    
    /*     */
    const unsigned n = 14;
    /*       v */
    const unsigned v = 5;
    /*      */
    const char A[MAXN][MAXN] = {
    {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
    {0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0},
    {0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1},
    {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0},
    {0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},
    {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0}
    };
    
    char used[MAXN];
    
    /*       */
    void DFS(unsigned i)
    { unsigned k;
      used[i] = 1;
      printf("%u ", i+1);
      for (k = 0; k < n; k++)
        if (A[i][k] && !used[k]) DFS(k);
    }
    
    int main(void) {
      unsigned k;
      for (k = 1; k < n; k++) used[k] = 0;
      printf("     %u: \n", v);
      DFS(v-1);
      printf("\n");
      return 0;
    }
    :

    Code:
    public class DFS {
    
    	//   
    	public static int n=14;
    	
    	//      v
    	public static int v=5;
    	
    	 //    
    	public static  char[][] matrix = 
        {
    	  {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    	  {1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    	  {0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
    	  {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
    	  {0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
    	  {0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0},
    	  {0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0},
    	  {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
    	  {0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1},
    	  {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0},
    	  {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0},
    	  {0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
    	  {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},
    	  {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0}
        };
    	  //
    	  public static char mask[] = new char[14];
    	  
    	//       
    	public static void DFS(int i){
    		int k;
    		mask[i]=1;
    		System.out.printf("%d ",i+1);
    		for(k=0;k<n;k++) {
    			if((matrix[i][k]) && (!mask[k]))
    			DFS(k);
    		}
    	}
    	
    	
    	public static void main(String[] args) {
    		for(int k=1;k<n;k++) mask[k]=0;
    		System.out.printf("        %d %n",v);
    		DFS(v-1);
    		System.out.println();
    	}
    }

  6. #6
    Registered User
    Join Date: Apr:2004
    Location: EU
    Posts: 141
    :
    Code:
    if((matrix[i][k]!=0) && (mask[k]==0))

  7. #7
    Registered User bombov's Avatar
    Join Date: Jan:2007
    Location:
    Posts: 260
    .

    :
    const unsigned n = 14;
    unsigned ?

  8. #8
    Registered User
    Join Date: Apr:2004
    Location: EU
    Posts: 141
    unsigned C++ e unsigned int.
    Java unsigned .
    - int short.

  9. #9
    Registered User bombov's Avatar
    Join Date: Jan:2007
    Location:
    Posts: 260
    , , int.

  10. #10
    philosophus duratea icaci's Avatar
    Join Date: Oct:2006
    Location: Aachen
    Posts: 2,698
    unsigned xxx, xxx char, short, int, long long long , , . 0 (2^n)-1, n , C .

    A , . used . C int ( char, ). int boolean A used, 0 false, 1 true . if (...) , C .
    Internet - it doesn't make you stupid, it just makes your stupidity more accessible to others

  11. #11
    Registered User bombov's Avatar
    Join Date: Jan:2007
    Location:
    Posts: 260
    @icaci
    .

    ctr+v .

  12. #12
    philosophus duratea icaci's Avatar
    Join Date: Oct:2006
    Location: Aachen
    Posts: 2,698
    "Replace in selection"? - 20
    Internet - it doesn't make you stupid, it just makes your stupidity more accessible to others

  13. #13
    Registered User bombov's Avatar
    Join Date: Jan:2007
    Location:
    Posts: 260
    , , -.

  14. #14

    Join Date: Sep:2005
    Location: Sofia
    Posts: 18,517
    Java char . -
    public static final char n = 14;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |