<C1DFC7D0BBFDBACE39372E687770>

Similar documents
歯9장.PDF

03장.스택.key

OCaml

untitled

프로그램을 학교 등지에서 조금이라도 배운 사람들을 위한 프로그래밍 노트 입니다. 저 역시 그 사람들 중 하나 입니다. 중고등학교 시절 학교 도서관, 새로 생긴 시립 도서관 등을 다니며 책을 보 고 정리하며 어느정도 독학으르 공부하긴 했지만, 자주 안하다 보면 금방 잊어

5.스택(강의자료).key

BMP 파일 처리

untitled

chap7.key

Microsoft PowerPoint - ch10 - 이진트리, AVL 트리, 트리 응용 pm0600

Microsoft PowerPoint - chap13-입출력라이브러리.pptx

C프로-3장c03逞풚

Chapter 4. LISTS

0. 표지에이름과학번을적으시오. (6) 1. 변수 x, y 가 integer type 이라가정하고다음빈칸에 x 와 y 의계산결과값을적으시오. (5) x = (3 + 7) * 6; x = 60 x = (12 + 6) / 2 * 3; x = 27 x = 3 * (8 / 4

Line (A) å j a k= i k #define max(a, b) (((a) >= (b))? (a) : (b)) long MaxSubseqSum0(int A[], unsigned Left, unsigned Right) { int Center, i; long Max

2010 초등부문제 1. 나, 아버지, 할아버지의나이관계가다음과같다. 나와아버지의나이차이는 30 이고, 아버지와할아버지의나이차이는 26이고, 나와할아버지의나이합은 90이다. 나는몇살인가? 2. 기약분수는분자와분모의최대공약수가 1 인분수이다. 분수 와분수 사이의 분수중에

K&R2 Reference Manual 번역본

untitled

untitled

untitled

歯엑셀모델링


, ( ),, ( ), 3, int kor[5]; int eng[5]; int Microsoft Windows 4 (ANSI C2 ) int kor[5] 20 # define #define SIZE 20 int a[10]; char c[10]; float

C 언어 프로그래밊 과제 풀이

chap01_time_complexity.key


13주-14주proc.PDF

RYWKVGWKJOFY.hwp

11강-힙정렬.ppt

중간고사

C++-¿Ïº®Çؼ³10Àå

chap 5: Trees

본 강의에 들어가기 전

歯처리.PDF

윈도우즈프로그래밍(1)

/chroot/lib/ /chroot/etc/

Microsoft PowerPoint - chap02-C프로그램시작하기.pptx

Microsoft PowerPoint - Java7.pptx


Javascript.pages

4. #include <stdio.h> #include <stdlib.h> int main() { functiona(); } void functiona() { printf("hihi\n"); } warning: conflicting types for functiona

05_tree

PowerPoint 프레젠테이션

int main(void) int a; int b; a=3; b=a+5; printf("a : %d \n", a); printf("b : %d \n", b); a b 3 a a+5 b &a(12ff60) &b(12ff54) 3 a 8 b printf(" a : %x \

ePapyrus PDF Document

PowerPoint 프레젠테이션

<C1DFB0EDB5EEBACE2E687770>

HW5 Exercise 1 (60pts) M interpreter with a simple type system M. M. M.., M (simple type system). M, M. M., M.

chap 5: Trees

Infinity(∞) Strategy

(Asynchronous Mode) ( 1, 5~8, 1~2) & (Parity) 1 ; * S erial Port (BIOS INT 14H) - 1 -

EBS-PDF컴퓨터일반-07-오

Visual Basic 반복문

Microsoft PowerPoint - chap05-제어문.pptx


< E20C6DFBFFEBEEE20C0DBBCBAC0BB20C0A7C7D12043BEF0BEEE20492E707074>

商用

歯MDI.PDF

HWP Document

Chapter 4. LISTS

Microsoft PowerPoint - ch07 - 포인터 pm0415

Chapter 4. LISTS


02 C h a p t e r Java

Microsoft PowerPoint - ch09 - 연결형리스트, Stack, Queue와 응용 pm0100

08장.트리

- 1 -

ABC 10장

PowerPoint 프레젠테이션

歯7장.PDF

chap7.PDF

학습목표 함수프로시저, 서브프로시저의의미를안다. 매개변수전달방식을학습한다. 함수를이용한프로그래밍한다. 2

IUPLDFSYXPPZ.hwp

<4D F736F F F696E74202D D20B9AEC0DABFAD2C20BDBAC6AEB8B2B0FA20C6C4C0CF20C0D4C3E2B7C2>

PowerPoint 프레젠테이션

2008 시도예선초등부문제 1. 다음은일정한규칙에따라수를늘어놓은것이다. 빈칸에가장알맞은수는? 2, 3, 5, 8, 12, 17, ( ) 2. A, B, C, D 가각각 0~9 까지숫자중에하나이고다른알파벳은다른숫자를나타낸 다. 다음식을만족하는 D 의값은? 3. 1 을 7

EA0015: 컴파일러

12-file.key

슬라이드 1

- 1 -

컴파일러

11장 포인터

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

Let G = (V, E) be a connected, undirected graph with a real-valued weight function w defined on E. Let A be a set of E, possibly empty, that is includ

슬라이드 1

(Humphery Kim) RAD Studio : h=p://tech.devgear.co.kr/ : h=p://blog.hjf.pe.kr/ Facebook : h=p://d.com/hjfactory :

Lab 5. 실습문제 (Double linked list)-1_해답.hwp

해양모델링 2장5~ :26 AM 페이지6 6 오픈소스 소프트웨어를 이용한 해양 모델링 물리적 해석 식 (2.1)의 좌변은 어떤 물질의 단위 시간당 변화율을 나타내며, 우변은 그 양을 나타낸 다. k 5 0이면 C는 처음 값 그대로 농

Microsoft PowerPoint - chap-11.pptx

untitled

1장. 유닉스 시스템 프로그래밍 개요

EMBARCADERO TECHNOLOGIES (Humphery Kim) RAD Studio : h=p://tech.devgear.co.kr/ : h=p://blog.hjf.pe.kr/ Facebook : h=p://d.com/hjfactory :

Microsoft PowerPoint - Chapter_04.pptx

Index Process Specification Data Dictionary

Microsoft PowerPoint - [2009] 02.pptx

Microsoft PowerPoint APUE(Intro).ppt

Microsoft PowerPoint - a10.ppt [호환 모드]

<443A5C4C C4B48555C B3E25C32C7D0B1E25CBCB3B0E8C7C1B7CEC1A7C6AE425CBED0C3E0C7C1B7CEB1D7B7A55C D616E2E637070>

쉽게 풀어쓴 C 프로그래밍

Transcription:

1. 다음은각단위의크기를나타낸표이다. 단위 h k M G T P E 크기 단위 c m μ n p f a 크기 위표를이용하면 1 M byte 는 km인가? 1 km 2 km byte 이고 1 mg 은 3 km 4 km g 임을알수있다. 그렇다면 1nm 는몇 5 km 3. 한변의길이가 1인단위정육면체를가로, 세로, 높이가각각 8개가되도록쌓아정육면체를만들었다. 이정육면체의겉표면을빨간색물감으로칠한후다시단위정육면체로분리하였다. 한면도색칠되지않은단위정육면체의개수는단한면만색칠된단위정육면체의개수의몇배인가? - 1 -

1 배 2 배 3 배 4 배 5 배 4. 다음과같은성질을만족하는최소의자연수를환상수라고한다. 성질 1. 2이상 10이하의수로나누어떨어지지않는다. 성질 2. 약수의개수가셋이상이다. 환상수의각자리수의합은얼마인가? 1 4 2 5 3 6 4 7 5 8 5. 이웃한모든교차점사이의거리가일정할때 A 에서 B 에이르는최단경로의개수는몇개인가? 1 6 개 2 8 개 3 12 개 4 16 개 5 20 개 - 2 -

6. 2진수를 8진수로바꿀때는 2 3 = 8이므로 2진수를끝에서부터세자리씩묶어주면 8진수로쉽게바꿀수있다. 예를들어 2진수 10101011 (2) 을 8진수로바꾸어주면다음과같이 253 (8) 이된다. 2 진수 1 0 1 0 1 0 1 1 8 진수 2 5 3 이와같은성질을이용하여 16 진수 ABC (16) 을 2 진수로바꾸었을때 1 의개수는몇개인가? 1 6 개 2 7 개 3 8 개 4 9 개 5 10 개 7. 유전자조작을통해만들어낸토끼는다음과같은특성을가지고있다. 특성 1. 모든토끼는태어나서성장하는데 1달이걸린다. 특성 2. 성장을마친후 1달이된한쌍의토끼는매달 2쌍의토끼를낳는다. 특성 3. 토끼는 1년이내에죽지않는다. 막성장을마친토끼한쌍을토끼장에넣었다. 5 달후의토끼는몇쌍이될까? 1 41 쌍 2 42 쌍 3 43 쌍 4 44 쌍 5 45 쌍 8. 지수는편의점에서아르바이트를하고있다. 이편의점에 5분동안손님이한명도찾아오지않을확률은이라고한다. 그렇다면이편의점에 10분동안손님이한명도찾아오지않을확률은? 1 2 3 4 5-3 -

K K K - 4 -

A B C D E F G H I J 13. 다음중트리의대한설명으로옳지않은것은? 1 임의의두노드 (node) 사이의경로 (path) 는유일하다. 2 사이클 (cycle) 이존재하지않는다. 3 이진트리에서단말노드 (terminal node) 의개수는분지수 (degree) 가 2인내부노드 (internal node) 의개수보다하나더많다. 4 루트노드 (root) 의분지수 (degree) 가가장크다. 5 모든노드의자식노드의개수의합은모든노드의부모노드의개수의합과같다. Push(A) A GetValue( ) Pop( ) IsEmpty() True( 또는 true) False( 또는 false) - 5 -

< VB > Sub main() End Sub S = "KOREA" For I = 1 To 5 If Not IsEmpty And GetValue() < Mid(S, I, 1) Then R = R + Pop() Push (Mid(S, I, 1)) Next I While Not IsEmpty() R = R + Pop() Wend Debug.Print R < VC++ > #include <stdio.h> void main() char s[6] = "KOREA"; char r[6] = ""; int rn = 0; int i; for ( i = 0; i < 5; i++ ) if (!IsEmpty() && Get() < s[i] ) r[rn++] = Pop(); Push( s[i] ); while (!IsEmpty() ) r[rn++] = Pop(); printf( "%s n", r ); < Delphi > $APPTYPE CONSOLE uses SysUtils; var - 6 -

s : string = 'KOREA'; r : string = ' '; rn : integer; i : integer; rn = 0; for i := 1 to 5 do if not IsEmpty() and (Get() < s[i]) then inc(rn); r[rn] := Pop(); Push(s[i]); while not IsEmpty() do inc(rn); r[rn] := Pop(); writeln(r); end. KOREA AEROK AEKOR KOAER ROKEA - 7 -

< VB > Sub main() End Sub N = 10 A = Array(1, 5, 3, 7, 4, 6, 9, 2, 5, 8) M = S = 0 For I = 0 To N - 1 S = S + A(I) If A(I) > M Then M = A(I) Next I T = S / N Debug.Print M + T < VC++ > #include <stdio.h> #define N 10-8 -

void main() int a[n] = 1, 5, 3, 7, 4, 6, 9, 2, 5, 8; int i; int m; int s, t; m = s = 0; for ( i = 0; i < N; i++ ) s += a[i]; if ( a[i] > m ) m = a[i]; t = s / N; printf( "%d n", m + t ); < Delphi > $APPTYPE CONSOLE uses SysUtils; const N = 10; var a : array [1..N] of integer = (1, 5, 3, 7, 4, 6, 9, 2, 5, 8); i : integer; m : integer; s, t : integer; m := 0; s := 0; for i := 1 to N do s := s + a[i]; if a[i] > m then m := a[i]; t := s div N; writeln(m + t); end. - 9 -

< VB > Sub main() N = 5 For I = 1 To N Next I End Sub < VC++ > Debug.Print Tab(I); For J = I To N Debug.Print Trim(J); Next J For J = N - 1 To I Step -1 Debug.Print Trim(J); Next J Debug.Print #include <stdio.h> void main() int n = 5; int i, j; for ( i = 1; i <= n; i++ ) for ( j = 1; j <= i; j++ ) printf( " " ); for ( j = i; j <= n; j++ ) printf( "%d", j ); for ( j = n - 1; j >= i; j-- ) printf( "%d", j ); printf(" n"); < Delphi > $APPTYPE CONSOLE - 10 -

uses SysUtils; var n : integer = 5; i, j : integer; for i := 1 to n do writeln; end. for j := 1 to i do write(' '); for j := i to n do write(j); for j := n - 1 downto i do write(j); < VB > Sub main() N = 1: S = 1 While (N < 100) Wend End Sub N = N + 2 S = S + N Debug.Print S < VC++ > #include <stdio.h> void main() int n, s; - 11 -

n = 1; s = 1; while ( n < 100 ) n += 2; s += n; printf( "%d n", s ); < Delphi > $APPTYPE CONSOLE uses SysUtils; var n : integer; s : integer; n := 1; s := 1; while n < 100 do n := n + 2; s := s + n; writeln(s); end. N( 또는 n) 은 < VB > Function F(N) As Integer If N = 0 Then F = 0 Else F = F(Int(N / 10)) + N Mod 10-12 -

End If End Function < VC++ > int f( int n ) if (n == 0) return 0; else return f(n / 10) + n % 10; < Delphi > function f(n: integer) : integer; if n = 0 then f := 0 else f := f(n div 10) + n mod 10; < VB > For I = 1 To N Next I If (A(I)) < M Then M = (A(I)) R = A(I) End If Sqr Abs Sgn Asc Val < VC++ > for ( i = 0; i < N; i++ ) if ( ( a[i] ) < m ) - 13 -

m = ( a[i] ); r = a[i]; abs < Delphi > for i := 1 to N do if (a[i]) < m then m := (a[i]); r := a[i]; abs < VB > Function F(N) As Integer If N < 3 Then F = N Mod 3 Else: F = F(N - 1) + F(N Mod 3) End If End Function Sub main() End Sub S = F(10) Debug.Print S < VC++ > #include <stdio.h> int f( int n ) if ( n < 3 ) return n % 3; return f( n - 1 ) + f ( n % 3 ); void main() int s = f( 10 ); - 14 -

printf( "%d n", s ); < Delphi > $APPTYPE CONSOLE uses SysUtils; function f(n : integer) : integer; if n < 3 then f := n mod 3 else f := f(n - 1) + f(n mod 3); var s : integer; s := f(10); writeln(s); end. 자신을제외한약수의합이 B가되고, B 자신을제외한약수의합이 A가될때이러한두수를우정수라고한다. 예를들어 220의자신을제외한약수의합은 284이고, 284의자신을제외한약수의합은 220이되어이둘은우정수가된다. 다음프로그램은 1000이하의모든우정수쌍을구하여출력하는프로그램이다. 빈칸에차례로들어갈내용으로알맞은것은? < VB > Function F(K) As Integer S = 0 For I = 1 To K - 1 If K Mod I = 0 Then S = S + I Next I F = S End Function Sub main() For I = 1 To 1000 A = F(I) B = F(A) - 15 -

If Then Debug.Print I; A Next I End Sub I = B And I < A I < B And I < A I > B And I < A I = B And I = A I < B And I = A < VC++ > #include <stdio.h> int f( int k ) int i; int s = 0; for ( i = 1; i < k; i++ ) if ( k % i == 0 ) s += i; return s; void main() int a, b; int i; for ( i = 1; i <= 1000; i++ ) a = f ( i ); b = f ( a ); if ( ) printf( "%d %d n", i, a ); i == b && i < a i < b && i < a i > b && i < a i == b && i == a i < b && i == a < Delphi > $APPTYPE CONSOLE uses SysUtils; function f(k : integer) : integer; var i : integer; s : integer; - 16 -

s := 0; for i := 1 to k - 1 do if k mod i = 0 then s := s + i; f := s; var a, b : integer; i : integer; for i := 1 to 1000 do a := f(i); b := f(a); if end. then writeln(i, ' ', a); (i = b) and (i < a) (i < b) and (i < a) (i > b) and (i < a) (i = b) and (i = a) (i < b) and (i = a) < VB > For I = 1 To 10 TMP = A(I) For J = I - 1 To 1 Step -1 If A(J) > TMP Then Next I Next J Else Exit For End If A(J + 1) = TMP A(J) = A(J + 1) A(J + 1) = A(J) A(J) = A(I) A(J + 1) = A(I) A(I + 1) = A(J) < VC++ > for ( i = 0; i < 10; i++ ) - 17 -

tmp = a[i]; for ( j = i - 1; j >= 0; j-- ) if ( a[j] > tmp ) ; else break; a[j + 1] = tmp; a[j] = a[j + 1] a[j + 1] = a[j] a[j] = a[i] a[j + 1] = a[i] a[i + 1] = a[j] < Delphi > for i := 0 to 9 do tmp := a[i]; for j := i - 1 downto 0 do if a[j] > tmp then else break; a[j + 1] := tmp; a[j] := a[j + 1] a[j + 1] := a[j] a[j] := a[i] a[j + 1] := a[i] a[i + 1] := a[j] < VB > Function F(K) A = 1: B = n While A <= B Wend C = (A + B) / 2 If P(C) = K Then F = C If P(C) > K Then B = C - 1 Else: A = C + 1 End If - 18 -

F = -1 End Function Sub main() End Sub... R = F(K)... < VC++ > int f( int k ) int a, b; int c; a = 1; b = n; while ( a <= b ) c = ( a + b ) / 2; if ( p[c] == k ) return c; if ( p[c] > k ) b = c - 1; else a = c + 1; return -1; void main()... r = f( k );... < Delphi > function f(k : integer) : integer; var a, b : integer; c : integer; a := 1; b := n; while a <= b do c := (a + b) div 2; if p[c] = k then f := c; - 19 -

if p[c] > k then b := c - 1 else a := c + 1; f := 1;... r := f( k );... end. < VB > For I = Int(N / 2) To 1 Step -1 J = I: Tmp = A(I) Do Next I K = J * 2 If K < N And A(K) < A(K + 1) Then K = J * 2 + 1 If A(K) > Tmp Then A(J) = A(K) J = K Else Exit Do End If Loop Until (K > N / 2) A(J) = Tmp < VC++ > for ( i = n / 2; i >= 1; i-- ) j = i; tmp = a[i]; do k = j * 2; if ( k < n && a[k] < a[k + 1] ) k = j * 2 + 1; - 20 -

if (a[k] > tmp) a[j] = a[k]; j = k; else break; while ( k <= n / 2 ); a[j] = tmp; < Delphi > for i := n div 2 downto 1 do j := i; tmp := a[i]; repeat k := j * 2; if (k < n) and (a[k] < a[k + 1]) then k := j * 2 + 1; if a[k] > tmp then a[j] := a[k]; j := k; end else break; until k > n div 2; a[j] := tmp; - 21 -

A B < VB > Sub F( ) End Sub For I = 1 To 10 C(I) = 0 Next I For I = 1 To 10 C(A(I)) = C(A(I)) + 1 Next I For I = 2 To 10 C(I) = C(I) + C(I - 1) Next I For I = 1 To 10 B(C(A(I))) = A(I) C(A(I)) = C(A(I)) - 1 Next I < VC > void f ( ) int i; for ( i = 1; i <= 10; i++ ) c[i] = 0; for ( i = 1; i <= 10; i++ ) c[a[i]]++; for ( i = 2; i <= 10; i++ ) c[i] += c[i - 1]; for ( i = 1; i <= 10; i++ ) - 22 -

b[c[a[i]]] = a[i]; c[a[i]]--; < Delphi > procedure f; var i : integer; for i := 1 to 10 do c[i] := 0; for i := 1 to 10 do inc(c[a[i]]); for i := 2 to 10 do c[i] := c[i] + c[i - 1]; for i := 1 to 10 do b[c[a[i]]] := a[i]; dec(c[a[i]]); - 23 -

A B C D E F C A D 6 5 4 6 5 6 5 6 3 6 2 < VB > - 24 -

Const MAX_N = 10000 Dim N As Integer Dim Dice(MAX_N, 6) As Integer Dim Pos(MAX_N, 6) As Integer Dim Max As Integer Sub InputData() End Sub Open "INPUT.TXT" For Input As #1 Input #1, N For I = 1 To N For J = 1 To 6 Next J, I Close #1 Input #1, Dice(I, J) Pos(I, Dice(I, J)) = J Sub OutputResult() End Sub Open "OUTPUT.TXT" For Output As #2 Print #2, Max Close #2 Sub main() InputData Opposite = Array( (1) ) For I = 1 To 6 Sum = 0 K1 = Dice(1, I) For J = 1 To N P = Pos(J, K1) O = Opposite(P) K2 = Dice(J, O) If K1 <> 6 And K2 <> 6 Then M = 6 ElseIf K1 <> 5 And K2 <> 5 Then - 25 -

Next I End Sub Next J M = 5 Else: M = 4 End If Sum = Sum + M (2) If Sum > Max Then Max = Sum OutputResult 1 6, 1, 2, 4, 5, 3 2 6, 2, 3, 4, 5, 1 3 6, 3, 2, 5, 1, 4, 4, 5, 2, 3, 1, 5, 4, 3, 2, 1 1 K1 = K2 2 K2 = K1 3 K1 = K1 + K2 K2 = K2 + K1 K1 = K1 + 1 < VC++ > #include <stdio.h> #define MAX_N 10000 int n; int dice[max_n][6], pos[max_n][6]; int opposite[6] = (1) ; int max; void Input () FILE *f = fopen ( "input.txt", "r" ); fscanf( f, "%d n", &n ); int i, j; for ( i = 0; i < n; i++ ) for ( j = 0; j < 6; j++ ) - 26 -

fscanf( f, "%d", &dice[i][j] ); pos[i][dice[i][j]] = j; fclose( f ); void Output () FILE *f = fopen ( "output.txt", "w" ); fprintf( f, "%d n", max ); fclose( f ); void main () int i, j; int k1, k2; int p, o; int m, sum;; Input(); for ( i = 0; i < 6; i++ ) sum = 0; k1 = dice[0][i]; for ( j = 0; j < n; j++ ) p = pos[j][k1]; o = opposite[p]; k2 = dice[j][o]; if ( k1!= 6 && k2!= 6 ) m = 6; else if ( k1!= 5 && k2!= 5 ) m = 5; else m = 4; sum += m; (2) ; if ( sum > max ) max = sum; Output(); - 27 -

1 5, 0, 1, 3, 4, 2 2 5, 1, 2, 3, 4, 0 3 5, 2, 1, 4, 0, 3 5, 3, 4, 1, 2, 0 5, 4, 3, 2, 1, 0 1 k1 = k2 2 k2 = k1 3 k1 += k2 k2 += k1 k1++ < Delphi > $APPTYPE CONSOLE uses SysUtils; const MAX_N = 10000; var n : integer; dice, pos : array[1..max_n, 1..6] of integer; opposite : array[1..6] of integer = ( (1) ); max : integer; procedure Input; var f : text; i, j : integer; assign(f, 'input.txt'); reset(f); readln(f, n); for i := 1 to n do for j := 1 to 6 do read(f, dice[i][j]); pos[i][dice[i][j]] := j; close(f); procedure Output; var f : text; assign(f, 'output.txt'); rewrite(f); writeln(f, max); - 28 -

close(f); var end. i, j : integer; k1, k2 : integer; p, o : integer; m, sum : integer; Input; for i := 1 to 6 do sum := 0; k1 := dice[1][i]; for j := 1 to n do p := pos[j][k1]; o := opposite[p]; k2 := dice[j][o]; if ( k1 <> 6 ) and ( k2 <> 6 ) then m := 6 else if ( k1 <> 5 ) and ( k2 <> 5 ) then m := 5 else m := 4; sum := sum + m; (2) ; if sum > max then max := sum; Output; 1 6, 1, 2, 4, 5, 3 2 6, 2, 3, 4, 5, 1 3 6, 3, 2, 5, 1, 4 6, 4, 5, 2, 3, 1, 5, 4, 3, 2, 1 1 k1 := k2 2 k2 := k1 3 k1 := k1 + k2 k2 := k2 + k1 k1) - 29 -

(1) (2) (3) (4) (5) (6) (7) 35 40 50 10 30 45 60-30 -

< VB > Const MAX_N = 50000 Dim N As Integer Dim M As Integer Dim Num(MAX_N) As Integer Dim Sum(MAX_N) As Integer Dim T(3, MAX_N) As Integer Dim Res As Integer Sub InputData() End Sub Open "INPUT.TXT" For Input As #1 Input #1, N For I = 1 To N Input #1, Num(I) Next I Input #1, M Close #1 Sub OutputResult() End Sub Open "OUTPUT.TXT" For Output As #2 Print #2, Res Close #2 Function Max(A, B) As Integer If (1) Then Max = A Else: Max = B End If End Function - 31 -

Sub main() End Sub InputData For I = 1 To M Sum(M) = Sum(M) + Num(I) Next I For I = M + 1 To N Sum(I) = (2) Next I For I = 1 To 3 For J = M * I To N T(I, J) = Max(T(I, J - 1), (3) ) Next J Next I Res = T(3, N) OutputResult A = B A > B A < B A <> B A Mod B = 0 Sum(I - 1) + Num(I) Sum(I - 1) - Num(I - M) Sum(I - 1) + Num(I - M) - Num(I) Sum(I - 1) + Num(I - M) + Num(I) Sum(I - 1) - Num(I - M) + Num(I) T(I - 1, J - M) + Sum(J) T(I, J - M) + Sum(J) T(I + 1, J - M + 1) + Sum(J) T(I - 1, J - M + 1) + Sum(J) T(I, J - M + 1) + Sum(J) < VC++ > #include <stdio.h> #define MAX_N 50000 int n, m; - 32 -

int num[max_n + 1], sum[max_n + 1]; int t[4][max_n + 1]; int res; void Input () FILE *f = fopen ( "input.txt", "r" ); fscanf( f, "%d n", &n ); for (int i = 1; i <= n; i++ ) fscanf( f, "%d", &num[i] ); fscanf( f, "%d n", &m ); fclose( f ); void Output () FILE *f = fopen ( "output.txt", "w" ); fprintf( f, "%d n", res ); fclose( f ); int max( int a, int b ) if ( (1) ) return a; else return b; void main () int i, j; Input(); for ( i = 1; i <= m; i++ ) sum[m] += num[i]; for ( i = m + 1; i <= n; i++ ) sum[i] = (2) ; for ( i = 1; i <= 3; i++ ) for ( j = m * i; j <= n; j++ ) t[i][j] = max( t[i][j - 1], (3) ); res = t[3][n]; Output(); - 33 -

a == b a > b a < b a!= b a % b == 0 sum[i - 1] + num[i] sum[i - 1] + num[i - m] sum[i - 1] + num[i - m] - num[i] sum[i - 1] + num[i - m] + num[i] sum[i - 1] - num[i - m] + num[i] t[i - 1][j - m] + sum[j] t[i][j - m] + sum[j] t[i + 1][j - m + 1] + sum[j] t[i - 1][j - m + 1] + sum[j] t[i][j - m + 1] + sum[j] < Delphi > $APPTYPE CONSOLE uses SysUtils; const MAX_N = 50000; var n, m : integer; num, sum : array[0..max_n] of integer; t : array[0..3, 0..MAX_N] of integer; res : integer; procedure Input; var f : text; i : integer; assign(f, 'input.txt'); reset(f); readln(f, n); for i := 1 to n do read(f, num[i]); readln(f, m); close(f); procedure Output; var f : text; assign(f, 'output.txt'); - 34 -

rewrite(f); writeln(f, res); close(f); function max( a, b : integer ) : integer; if (1) then max := a else max := b; var i, j : integer; Input; for i := 1 to m do sum[m] := sum[m] + num[i]; for i := m + 1 to n do sum[i] := (2) ; for i := 1 to 3 do for j := m * i to n do t[i, j] := max( t[i][j - 1], (3) ); res := t[3][n]; Output; end. a = b a > b a < b a <> b a mod b = 0 sum[i - 1] + num[i] sum[i - 1] + num[i - m] sum[i - 1] + num[i - m] - num[i] sum[i - 1] + num[i - m] + num[i] sum[i - 1] - num[i - m] + num[i] t[i - 1][j - m] + sum[j] t[i][j - m] + sum[j] t[i + 1][j - m + 1] + sum[j] t[i - 1][j - m + 1] + sum[j] t[i][j - m + 1] + sum[j] - 35 -

- 36 -