Results 1 to 3 of 3
Thread: ?
Hybrid View
-
17th January 2010 17:10 #1Registered 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"); }
-
17th January 2010 20:11 #2
, , 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
-
17th January 2010 21:04 #3Registered User
Join Date: Apr:2007
Location:
Posts: 184




Reply With Quote

Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in