ABC053_B
文字列反転の問題
文字列反転は次のようにする.
string str = "abcde"; reverse(str.begin(),str.end());//"edcba"
#include <bits/stdc++.h> using namespace std; int main() { string str; cin>>str; int start=0,end=0; for(int i=0;i<str.size();i++){ start++; if(str[i]=='A')break; } reverse(str.begin(),str.end()); for(int i=0;i<str.size();i++){ end++; if(str[i]=='Z')break; } end = str.size()-end+1; cout<<end-start+1<<endl; return 0; }
ABC055_B
factorialを求める問題
大きい数値はll型を使う.
int型(4byte)の範囲は20億くらいを目安にする.
#include <bits/stdc++.h> using namespace std; #define ll long long int #define MOD (ll)1e9+7 #define MAX(X,Y) ((X)>(Y)?(X):(Y)) #define MIN(X,Y) ((X)<(Y)?(X):(Y)) int fact(int x) { ll res = 1; for(int i=1;i<=x;i++){ res *= i; res %= MOD; } return res; } int main() { int x; cin>>x; cout<<fact(x)<<endl; return 0; }
ABC025_A
文字列についての問題
文字列の要素1つはchar型だと知った.
ex)
string str = "abcde"; cout<<typeid(str[1]).name()<<endl; //c
よってsubstr(ポインタの位置,そこから何文字分?)を使って部分文字列を使った.
#include <bits/stdc++.h> using namespace std; int main() { string s; int n; vector<string> ss; cin>>s>>n; sort(s.begin(),s.end()); for(int i=0;i<5;i++){ for(int j=0;j<5;j++){ string new_ss = s.substr(i,1)+s.substr(j,1); ss.push_back(new_ss); } } cout<<ss[n-1]<<endl; return 0; }
標準ライブラリ一括インクルード
#include <bits/stdc++.h>
ABC050_A
文字列を分割して数値にする問題
#include <iostream> #include <cstdio> #include <string> #include <sstream> #include <vector> using namespace std; int stoi(std::string str){ int ret; std::stringstream ss; ss<<str; ss>>ret; return ret; } vector<string> split(const string &s, char delim) { /* 文字列分割してvector<string>を返す */ vector<string> elems; stringstream ss(s); string item; while (getline(ss, item, delim)) { if (!item.empty()) { elems.push_back(item); } } return elems; } int main() { string Str; vector<string> ans; int a,b; getline(cin, Str);//空白ごと1行入力 ans = split(Str,' '); a = stoi(ans[0]); b = stoi(ans[2]); if(ans[1]=="+") printf("%d\n",a+b); else printf("%d\n",a-b); return 0; }
空白を含めて一行入力したい場合は
getline(cin,str);
ABC051_A
文字列の置換
www.geocities.jp
#include<iostream> #include<string> using namespace std; // 文字列を置換する std::string Replace(std::string String, std::string From, std::string To ) { std::string::size_type Pos( String.find( From ) ); while( Pos != std::string::npos ) { String.replace( Pos, From.length(), To ); Pos = String.find( From, Pos + To.length() );//さっきまで探してた位置以降のFromを探す } return String; } int main() { string s; cin >> s; s = Replace(s,","," "); cout<<s<<endl; return 0; }
Newton法で平方根を求める
(define (sqrt-iter guess x) (if (good-enough? guess x) guess (sqrt-iter (imporve guess x) x))) (define (improve guess x) (average guess (/ x guess))) (define (average x y) (/ (+ x y) 2)) (define (good-enough? guess x) (< (abs (- (square guess) x)) 0.001)) (define (sqrt x) (sqrt-iter 1.0 x))
C91の反省
C91の反省と忘備録
配布物
- 前日5日間くらいで仕上げたので完成度がかなり低かった
- 製本が上手く出来なかった(製本テープを使う,業者に依頼するなど必要)
- ゲームのクオリティが低い
- 自宅で印刷をする場合,かなりの時間と手間がかかる
設営
Python
Pythonでimport thisとやると下のような文が出ることが分かった.
今日から「Effective Python」を読み始める.
Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!
遺伝的アルゴリズムで画像再現
遺伝的アルゴリズムを用いて画像を再現するというプロジェクトを行った.
まだまだ検討箇所があるので現在の結果を貼っておく.
目標の画像
0世代
1000世代
ツイートは0~800世代くらい
https://twitter.com/vockyX/status/816646900392656897
今後の活動
・1000世代後に効果を発揮できるように評価関数を改良する
(1000世代くらいになると概形はほぼ完成しているので色を滑らかにするという目的に変える)
・低画質→高画質への変換器を作る