(旧)研究メモ

kennkyuumemo

C++

プログラムの 計算時間を知りたい時

#include <time.h> int main(){ clock_t time_start = 0; clock_t time_end = 0; time_start = clock(); //時間を測りたい処理 time_end = clock(); cout << "Computing time is " << double(time_end-time_start)/CLOCKS_PER_SEC << " [s]" << endl; }</time.h>

構造体

struct 構造体タグ名 {メンバたち}; struct 構造体タグ名 構造体変数名; 例 struct date { int year; int month; int day; }; struct date d = {2014, 5, 15}; cout << "Today is "d.year << "/" << d.month << "/" << d.day << endl; 出力は Today is 2014/…

vector便利

配列って最初定義するときに要素数が必要だけど、vectorならいらない。基本的な使い方は、イテレータと合わせて #include <vector> #include <iostream> using namespace std; int main(){ vector<int> array; int i; for(i=0;i<10;i++){ array.push_back(i); } for(i=0;i<10;i++){ </int></iostream></vector>…

Geant4でのデータ収集の仕方(1)

Geant4でデータを取る(スコアリング)ために用意されているもの Hit 検出器のsensitiveな領域内での、Trackの物理相互作用のスナップショット。G4Stepオブジェクトに属する以下のような物理量を集める そのStepの位置と時刻 Trackの運動量、エネルギー そのSt…

サーチその2

リニアサーチは単純でとてもわかりやすいがもう少し高速化しようと思えばできる。 リニアサーチでは配列の範囲内で目的の数字と一致するまで、という繰り返し部分 while(n < num && a[n] != x){ n++; } if(n < num){ return n; } があったがここでいちいち配…

サーチ

サーチのアルゴリズム。リニアサーチは配列の前から順番に、見つけたいものを探す。 #include <stdio.h> #include <stdlib.h> #include <iostream> #include <time.h> #define NOT_FOUND (-1) #define N (10) using namespace std; int Linear_search(int x, int *a, int num){ int n = 0; while(n </time.h></iostream></stdlib.h></stdio.h>…

サーチ

サーチのアルゴリズム。リニアサーチは配列の前から順番に、見つけたいものを探す。 #include <stdio.h> #include <stdlib.h> #include <iostream> #include <time.h> #define NOT_FOUND (-1) #define N (10) using namespace std; int Linear_search(int x, int *a, int num){ int n = 0; while(n </time.h></iostream></stdlib.h></stdio.h>…

バブルソート

最近ソートについて勉強し直したのでメモしときます。ばらばらな配列を、前から順番に見ていって隣同士入れ替えていくのを何回も繰り返す。 #include <stdio.h> #include <stdlib.h> #include <time.h> #include <iostream> #define N 10 int x[N]; using namespace std; void BabbleSort(void){ i</iostream></time.h></stdlib.h></stdio.h>…