2017-07-05 ~ 2017-07-18
Dynetのインストール
gccはlinuxbrewで入れたものを使う
% which gcc gcc (Homebrew gcc 5.3.0) 5.3.0 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Eigen3をインストール
brew install eigen
glibcのバージョン
brew install glibc
> glibc: stable 2.19
> The GNU C Library
リポジトリをクローン
git clone https://github.com/clab/dynet.git
ビルドの準備
cd dynet mkdir build cd build cmake .. -DEIGEN3_INCLUDE_DIR=$HOME/.linuxbrew/include/eigen3/ -DPYTHON=`which python``
ビルド
make -j20 <|| 実行確認 >|sh| ./examples/train_xor # 動いた
c++までは動作を確認した.
-
- -
cd python
python setup.py install
実行
python >> import dynet # ImportError: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by ./_dynet.so)
残念
あとで頑張る
考えられる原因
連続する整数の和
Sum of Consecutive Integers | Aizu Online Judge
整数Nがあたえられる.
2つ以上の連続する整数の組み合わせのうち,
和がN(1<=N<=1000)に等しくなるものの数を求める.
1. 連続する整数,つまり初項1,等差1の等差数列の部分列
2. 2点(左右)が定まれば良いので,全探索できる
//#define _GRIBCXX_DEBUG #include <bits/stdc++.h> # define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; int sum (int l, int r) { return (r*(r+1)-l*(l-1)) / 2; } int main() { int n; while (cin >> n, n) { int l, r; int ans = 0; for (int l=1; l<=n; l++) { for (int r=l+1; r<=n; r++) { int ret = sum(l, r); /* if (ret == n) cout << l << ", " << r << "= " << ret << endl; */ if (ret == n) ans++; } } cout << ans << endl; } return 0; }
Keitai Message
Keitai Message | Aizu Online Judge
つらいやるだけ問題.
1. ヘッドを用意して順次更新
2. 0が入力されたら出力にpushしてヘッドを初期化
//#define _GRIBCXX_DEBUG #include <bits/stdc++.h> # define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; class Keyboard { public: string input, output; vector<vector<char>> keyboard; string make_output(); Keyboard(string input) : input(input) { // IMPORTANT: vector<vector<char>> keyboard; // これをここでやってしまうとメンバ変数とは違う // 形で初期化が行われてしまい外部から参照できなくなる keyboard.resize(10); keyboard[0] = vector<char>({'A'}); keyboard[1] = vector<char>({'.', ',', '!', '?', ' '}); keyboard[2] = vector<char>({'a', 'b', 'c'}); keyboard[3] = vector<char>({'d', 'e', 'f'}); keyboard[4] = vector<char>({'g', 'h', 'i'}); keyboard[5] = vector<char>({'j', 'k', 'l'}); keyboard[6] = vector<char>({'m', 'n', 'o'}); keyboard[7] = vector<char>({'p', 'q', 'r', 's'}); keyboard[8] = vector<char>({'t', 'u', 'v'}); keyboard[9] = vector<char>({'w', 'x', 'y', 'z'}); } }; string Keyboard::make_output() { int curr; int prev = -1; int freq = 0; output = ""; rep (i, input.size()) { curr = (int)input[i] - 48; // ascii code // 一緒 or 初め if (curr == prev || prev == -1) freq++; // 入力確定 if (curr == 0) { if (prev != -1) { freq--; int qindex = keyboard[prev].size(); /* cout << "i, j: " << prev << "," << freq % qindex << endl; */ /* cout << keyboard[prev][freq%qindex] << endl; */ output += keyboard[prev][freq%qindex]; } // 初期化 prev = -1; freq = 0; } else prev = curr; } return output; } int main() { int n; string s; cin >> n; rep (i, n) { cin >> s; Keyboard k = Keyboard(s); cout << k.make_output() << endl; } return 0; }
お姫様のギャンブル
Princess's Gamble | Aizu Online Judge
実際にシミュレーションをする.
分母に0が来ることがあるので0除算の恐れがある.
場合分けを行えば良い.
//#define _GRIBCXX_DEBUG #include <bits/stdc++.h> # define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; int main() { int n, m, f; while (cin >> n >> m >> f, n) { vector<int> x(n); rep (i, n) cin >> x[i]; float sum = 0; rep (i, n) sum += 100.0*x[i]; float ret = sum - ((float)f/100) * sum; int ans = ret / x[m-1]; cout << (ans > 0 ? ans : 0) << endl; } return 0; }
C++で文字列を数値にする
c_strでconst char*に変換するといける
普通はどうするものなのかよくわかっていない
(そもそも文字列->数値な変換が発生すること自体がダメ?)
//#define _GRIBCXX_DEBUG #include <bits/stdc++.h> # define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; int main() { string a = "53"; int i = atoi(a.c_str()); cout << i << endl; return 0; }