Results 1 to 3 of 3

Thread: ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date: Feb:2006
    Location: Pleven
    Posts: 36

    ?

    ! . . !


    . N ( 1, 2, 3,..., N), , : m . , N = 5 m = 2, : 1, 3, 5, 2, 4, 1, 3, 5, 2, 4, 1 .. -. , 4.
    last, N (1 < N < 1000) . - m , - , .
    1


    5 4
    2
    2


    20 13
    7

    Code:
    #include <iostream>
    #define MAX 1000
      using namespace std;
      void init(int reg[], int cnt)
        {
          for(int i = 0; i < cnt; i++)
            reg[i] = i+1;
        }
      int main()
        {
          int i=0, S, s=0, br = 0, max = 0, a[MAX], k, n;
          cin >> n;
          init(a, n);
          cin >> S;
          do
            {
              i++;
              do
                {
                  br++;
                  if(a[s] == S)
                    {
                      if(max < br)
                        {
                          max = br;
                          k = i;
                        }
                      s = 0; br = 0; break;
                    }
                  s+=i;
                  if(s >= n)
                    s = i-1;
                }
              while(s != 0);
            }
          while(i < n);
          cout << k;
          system("pause");
        }

  2. #2
    Registered User genn's Avatar
    Join Date: Feb:2003
    Location:
    Posts: 1,215
    , , S, s, k, n .
    , , , .

    , :

    Code:
    int* init(  int nCount )
    {
    	int* pRegions	= new int[nCount];
    	for( int i = 0; i < nCount; i++ )
    	{
    		pRegions[i]	= i + 1;
    	}
    
    	return pRegions;
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	int nStep			= 3;
    	int nSpecial		= 5;
    	int nRegionsCount	= 15;
    	
    	int* pRegions	= init( nRegionsCount );
    		
    	for( int i = 0; i < nStep; i++ )
    	{
    		printf( "=== Cycle: %d ===\n", i );
    
    		int k = i;
    
    		while( k < nRegionsCount )
    		{
    			if( k  != nSpecial - 1 )
    			{
    				printf( "--> Shutdown No. %d\n", pRegions[k] );
    			}
    			k += nStep;
    		}
    	}
    
    	printf( "\n--> Shutdown Special No. %d\n", pRegions[nSpecial-1] );
    
    	delete[] pRegions;
    	return 0;
    }
    :

    Code:
    === Cycle: 0 ===
    --> Shutdown No. 1
    --> Shutdown No. 4
    --> Shutdown No. 7
    --> Shutdown No. 10
    --> Shutdown No. 13
    === Cycle: 1 ===
    --> Shutdown No. 2
    --> Shutdown No. 8
    --> Shutdown No. 11
    --> Shutdown No. 14
    === Cycle: 2 ===
    --> Shutdown No. 3
    --> Shutdown No. 6
    --> Shutdown No. 9
    --> Shutdown No. 12
    --> Shutdown No. 15
    
    --> Shutdown Special No. 5
    , ?

  3. #3
    Registered User
    Join Date: Apr:2007
    Location:
    Posts: 184

    Thumbs down

    Quote Originally Posted by gogorus View Post
    Code:
                  s+=i;
                  if(s >= n)
                    s = i-1;
    Code:
                  s+=i;
                  if(s >= n)
                    s = s - n;
    , s 0, br. - - i++; s = 0; br = 0;

    genn, .

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 |