忍者ブログ
19 March

[PR]

×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

26 August

2048AI

6月頃に書いた2048のAIのソースコードをうpします。

2048についてはこちらで実際にやってみてください。
http://gabrielecirulli.github.io/2048/

3手先まで、空きマスが4マス未満になったら4手先まで(にしてるけどあんまり意味なさそう)
ミニマックス法(?)で探索してるつもり。

盤面の評価は
1.隣り合うタイルの数値の差が小さいほど良い。
2.左上に大きい数字があるほど良い。
で決定しています。

ちゃんと実装できていない可能性大です。

一応1024までは安定、時々2048・4096ぐらいの精度です。

ソースはこちら
https://gist.github.com/tkzw21/26360f174e2055e994df
PR
21 June

メモリの確保場所のメモ


前の方にあるのがスッタク領域で
後ろの方にあるのがヒープ領域ってことかな。


#include<string>
#include<cstdio>
#include<iostream>

using namespace std;

int ga;
int garray[10];
int main(){
	int a;
	int* array = new int[10];

	string s;
	s += \'a\';

	printf(\"ga\'s  address     = %p\\n\",&a);
	printf(\"a\'s  address      = %p\\n\",&ga);
	printf(\"array\'s  address  = %p\\n\",array);
	printf(\"garray\'s  address = %p\\n\",&garray);
	printf(\"s\'s  address      = %p\\n\",&s);
	printf(\"s[0]\'s  address   = %p\\n\",&s[0]);

	return 0;
}

実行結果
ga's  address    = 0x22aa74
a's  address    = 0x100406020
array's  address    = 0x600028730
garray's  address    = 0x100406040
s's  address    = 0x22aa60
s[0]'s  address    = 0x600061ce8
27 April

SRM618 div2 easy,med

問題文

http://community.topcoder.com/stat?c=problem_statement&pm=13072
http://community.topcoder.com/stat?c=problem_statement&pm=13147

Easy

タップするとアルファベット順に進む携帯がある。
入力に対し何回タップすればいいか合計を返せ。

Med

1.全部大文字
2.同じ文字が連続しない
3.xyxyのような部分列が存在しない(x,y∈文字)
1~3を与えられた文字列が満たすかどうか返せ。

感想とか

Easy

文字コードで足してくだけ。

Med

スマートじゃなく雑に全探索しました。
http://ideone.com/MKkvRp
27 March

SRM612 div2 500

問題文

http://community.topcoder.com/stat?c=problem_statement&pm=13041

smiles
個絵文字を入力したいとき、
・今入力されている絵文字を全部クリップボードへコピーする。
・クリップボードからペーストする。
の2種類の操作ができる。
操作する回数の最小値を求めよ。(絵文字は最初に1個入力されている)


感想

DFSが使えて嬉しかったので久々の更新w
(間違っているかもしれません。)


class EmoticonsDiv2 {

	public:
	int printSmiles(int smiles) {
		int ans;
		ans = dfs(1,2,smiles);
		return ans+2;
	}

	int dfs(int clip,int now,int goal){
		int ret = INF;

		if(now == goal)return 0;
		if(now > goal)return INF;
		for(int i=0;i<2;i++){
			if(i==1)ret = min(ret,dfs(clip,now+clip,goal)+1);
			if(i==0)ret = min(ret,dfs(now,now+now,goal)+2);
		}
		return ret;
	}
};