software2-lecture

Similar documents
C言語によるアルゴリズムとデータ構造

/* do-while */ #include <stdio.h> #include <math.h> int main(void) double val1, val2, arith_mean, geo_mean; printf( \n ); do printf( ); scanf( %lf, &v

‚æ4›ñ

double float

(search: ) [1] ( ) 2 (linear search) (sequential search) 1

PowerPoint Presentation

Microsoft Word - Cプログラミング演習(10)

Cプログラミング - 第8回 構造体と再帰

3.1 stdio.h iostream List.2 using namespace std C printf ( ) %d %f %s %d C++ cout cout List.2 Hello World! cout << float a = 1.2f; int b = 3; cout <<

P05.ppt


1 return main() { main main C 1 戻り値の型 関数名 引数 関数ブロックをあらわす中括弧 main() 関数の定義 int main(void){ printf("hello World!!\n"); return 0; 戻り値 1: main() 2.2 C main

C¥×¥í¥°¥é¥ß¥ó¥° ÆþÌç

ex01.dvi

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裵²ó ¨¡ À©¸æ¹½Â¤¡§¾ò·ïʬ´ô ¨¡

mstrcpy char *mstrcpy(const char *src); mstrcpy malloc (main free ) stdio.h fgets char *fgets(char *s, int size, FILE *stream); s size ( )

void hash1_init(int *array) int i; for (i = 0; i < HASHSIZE; i++) array[i] = EMPTY; /* i EMPTY */ void hash1_insert(int *array, int n) if (n < 0 n >=

18 C ( ) hello world.c 1 #include <stdio.h> 2 3 main() 4 { 5 printf("hello World\n"); 6 } [ ] [ ] #include <stdio.h> % cc hello_world.c %./a.o

[1] #include<stdio.h> main() { printf("hello, world."); return 0; } (G1) int long int float ± ±

新・明解C言語 ポインタ完全攻略

[ 1] 1 Hello World!! 1 #include <s t d i o. h> 2 3 int main ( ) { 4 5 p r i n t f ( H e l l o World!! \ n ) ; 6 7 return 0 ; 8 } 1:

超初心者用

Cプログラミング1(再) 第2回

r07.dvi

I. Backus-Naur BNF : N N 0 N N N N N N 0, 1 BNF N N 0 11 (parse tree) 11 (1) (2) (3) (4) II. 0(0 101)* (

ohp07.dvi

double 2 std::cin, std::cout 1.2 C fopen() fclose() C++ std::fstream 1-3 #include <fstream> std::fstream fout; int a = 123; fout.open( "data.t

ex01.dvi

新・明解C言語で学ぶアルゴリズムとデータ構造

program.dvi

ex14.dvi

02

1-4 int a; std::cin >> a; std::cout << "a = " << a << std::endl; C++( 1-4 ) stdio.h iostream iostream.h C++ include.h 1-4 scanf() std::cin >>

PowerPoint プレゼンテーション


Original : Hello World! (0x0xbfab85e0) Copy : Hello World! (0x0x804a050) fgets mstrcpy malloc mstrcpy (main ) mstrcpy malloc free fgets stream 1 ( \n


P06.ppt

PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU

O(N) ( ) log 2 N

情報処理演習 B8クラス

debug ( ) 1) ( ) 2) ( ) assert, printf ( ) Japan Advanced Institute of Science and Technology

Taro-再帰関数Ⅱ(公開版).jtd

untitled

8 / 0 1 i++ i 1 i-- i C !!! C 2

I. Backus-Naur BNF S + S S * S S x S +, *, x BNF S (parse tree) : * x + x x S * S x + S S S x x (1) * x x * x (2) * + x x x (3) + x * x + x x (4) * *

C C UNIX C ( ) 4 1 HTML 1

1 C STL(1) C C C libc C C C++ STL(Standard Template Library ) libc libc C++ C STL libc STL iostream Algorithm libc STL string vector l

橡Pro PDF

新・明解C言語 実践編

:30 12:00 I. I VI II. III. IV. a d V. VI

Taro-リストⅢ(公開版).jtd

プログラミング方法論 II 第 14,15 回 ( 担当 : 鈴木伸夫 ) 問題 17. x 座標と y 座標をメンバに持つ構造体 Point を作成せよ 但し座標 は double 型とする typedef struct{ (a) x; (b) y; } Point; 問題 18. 問題 17 の

main

(300, 150) 120 getchar() HgBox(x, y, w, h) (x, y), w, h #include <stdio.h> #include <handy.h> int main(void) { int i; double w, h; } HgO

tuat1.dvi

II ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 D

Microsoft Word - Cプログラミング演習(12)

I 2 tutimura/ I 2 p.1/??

C による数値計算法入門 ( 第 2 版 ) 新装版 サンプルページ この本の定価 判型などは, 以下の URL からご覧いただけます. このサンプルページの内容は, 新装版 1 刷発行時のものです.

gengo1-11

C 2 / 21 1 y = x 1.1 lagrange.c 1 / Laglange / 2 #include <stdio.h> 3 #include <math.h> 4 int main() 5 { 6 float x[10], y[10]; 7 float xx, pn, p; 8 in

: CR (0x0d) LF (0x0a) line separator CR Mac LF UNIX CR+LF MS-DOS WINDOWS Japan Advanced Institute of Science and Technology

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() malloc 2 #include <stdio.h> #include

第2回

DOPRI5.dvi

lexex.dvi

BW BW

cpp1.dvi

02: 変数と標準入出力

:30 12:00 I. I VI II. III. IV. a d V. VI

第5回お試しアカウント付き並列プログラミング講習会

PowerPoint Presentation

untitled

02: 変数と標準入出力

untitled

PowerPoint プレゼンテーション

新版明解C言語 実践編

I ASCII ( ) NUL 16 DLE SP P p 1 SOH 17 DC1! 1 A Q a q STX 2 18 DC2 " 2 B R b

問 2 ( 型変換 ) 次のプログラムを実行しても正しい結果が得られない 何が間違いかを指摘し 正しく修正せよ ただし int サイズが 2 バイト long サイズが 4 バイトの処理系での演算を仮定する #include <stdio.h> int main( void ) { int a =

‚æ2›ñ C„¾„ê‡Ìš|

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1

PowerPoint プレゼンテーション

P02.ppt

Microsoft Word - Training10_プリプロセッサ.docx

Microsoft PowerPoint - 11th.ppt [互換モード]

tuat2.dvi

画像ファイルを扱う これまでに学んだ条件分岐, 繰り返し, 配列, ファイル入出力を使って, 画像を扱うプログラムにチャレンジしてみよう

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() 2 double *a[ ]; double 1 malloc() dou

Microsoft PowerPoint - 説明3_if文switch文(C_guide3)【2015新教材対応確認済み】.pptx

64bit SSE2 SSE2 FPU Visual C++ 64bit Inline Assembler 4 FPU SSE2 4.1 FPU Control Word FPU 16bit R R R IC RC(2) PC(2) R R PM UM OM ZM DM IM R: reserved

(1/2) 2/45 HPC top runner application programmer PC-9801F N88-BASIC Quick BASIC + DOS ( ) BCB Windows Percolation, Event-driven MD ActionScript Flash

Taro-リストⅠ(公開版).jtd

Minimum C Minimum C Minimum C BNF T okenseq W hite Any D

ex12.dvi

02: 変数と標準入出力

Microsoft Word - no15.docx

2 P.S.P.T. P.S.P.T. wiki 26

新版明解C言語入門編

A/B (2010/10/08) Ver kurino/2010/soft/soft.html A/B

Transcription:

! C!! assert!!!!!

! C!! assert!!!!!

!!!! int factorial(int n) { if (n == 0) return 1; } return n * factorial(n - 1);

factorial()! factorial(4) 4*6=24 4*factorial(3) 3*2=6 3*factorial(2) 2*1=2 2*factorial(1) 1*1=1 1*factorial(0) if (n == 0) return 1; 1

!! Euclid s algorithm!! m n (m n) n m n while int euclid(int m, int n) { int remainder; int euclid(int m, int n) { int remainder = m % n; } while ((remainder = m % n)!= 0) { m = n; n = remainder; } return n; } if (remainder == 0) return n; else return euclid(n, remainder);

!!! int factorial(int n) { if (n == 0) return 1; } return n * factorial(n - 1); int euclid(int m, int n) { int remainder = m % n; } if (remainder == 0) return n; else return euclid(n, remainder);

! #include <stdio.h> void test(int *a) { printf( %d\n,(*a)++); test(a); } int main(void) { int a = 0; test(&a); return 0; } ==

!! :!!!

! size_t fread(void* data, size_t size, size_t nitems, FILE* fp); size nitems size_t fwrite(void* data, size_t size, size_t nitems, FILE *fp); size nitems 10

writebinaryfile.c! 1000 double 2! ->! 1! size_t! 1000! gcc -o writebinaryfile writebinaryfile.c./writebinaryfile data.txt data.dat

1! : fread!! malloc!!!! time time./readbinaryfile data.dat

! C!!!assert!!!!

!!!!!!!!

! Knapsack Problem!! W nx max v i x i i=1 subject to nx i=1 w i x i apple W, x i 2 {0, 1} 0-1 http://en.wikipedia.org/wiki/knapsack_problem

!! 0 0 0 0 0 0 0 1 2 2 W = 15 4 12 10 4 2 2 0 1 0 10 4 0 1 1 12 6 1 0 0 4 12 1 0 1 6 14 1 1 0 14 16 1 1 1 16 18

! $ gcc -Wall -o knapsack knapsack.c!! 10 $./knapsack 10 70.0!! NG

main! const (assert ) const int max_items = 100; 100 max number of items

! Itemset *init_itemset(int, int);!! void free_itemset(itemset*)! free! void save_itemset(char *, Itemset*)!! double solve(itemset*, double, int*)!! double search(int, Itemset*, double, int*, double, double)!solve!

search()!! i!

search() double search(int index, const Itemset *list, double capacity, int *flag,double sum_v, double sum_w) { int max_index = list->number; assert(index >= 0 && sum_v >=0 && sum_w >= 0); if (index == max_index) { for (int i = 0 ; i < max_index ; i++){ printf("%d", flags[i]); } printf(", total_value = %5.1f, total_weight = %5.1f\n", sum_v, sum_w); return sum_v; } i flags[index] = 0; const double v0 = search(index+1, list, capacity, flags, sum_v, sum_w); flags[index] = 1; const double v1 = search(index+1, list, capacity, flags, sum_v + list- >value[index], sum_w + list->weight[index]); } return (v0 > v1)? v0 : v1; "

solve()! search()!0!! flags double solve(const Itemset *list, double capacity) { unsigned char *flags = (unsigned char*)calloc(list->number, sizeof(unsigned char)); double max_value = search(0,list,capacity,flags, 0.0, 0.0); free(flags); return max_value; }

12 4 12 16 10 4 2 2 0 1 16 0 1 2 12 0 1 6 16 0 1 0 1 0 1 0 1 0 2 10 12 4 6 14 16 search O(2^n)

main() 1. 2. 3. solve()

2 1. knapsack.c - : - 2. - : search -> - flags

DP! DP! [ ]

! C!!!assert!!!!

!! A B

tsp.c! $ gcc -Wall -o tsp tsp.c lm!!! $./tsp city10seed3.dat!! gencity.c ->

tsp.c!!!!city[i]! i (0 i < n)!route[j]! j! route[0] = 0 0!!visited[k]! k

tsp.c c 0 c 3 route[0] = 0 route[1] = 2 route[2] = 4 route[3] = 1 route[4] = 3 c 2 c 4 c 1

! O ( n 1)! ) 1 2 3 20 2 3 1 3 1 2 1.2 10 17 3 2 3 1 2 1

! tsp.c! [ ]! route!!!

hill climbing!! 1. 2. 3. 2!!!!

!!!! 04123 04321 0 4 0 4 1 2 3 1 3 1 2 3

! 2 2! 2 ->!! 2!! 0 4 0 4 1 2 3 1 3 1 2 3

12/19 1. helloworld.c Hello,World 2. fibo(n) O(log n) 3. knapsack.c 4. 5.

ITC-LMS! :! / zip tar.gz!git archive zip!soft-12-10-nnnnnnnn.zip SOFT-12-10-NNNNNNNN.tar.gz! NNNNNNNN! J J???????!![ ]![ ] 38

!! T, r (0 < r < 1) 1. 2.! exp(d/t)! d = 3. T T rt 4. T 2

!!!! T! T!!! T r