diff --git a/a.cpp b/a.cpp new file mode 100644 index 0000000..e67cd7e --- /dev/null +++ b/a.cpp @@ -0,0 +1,115 @@ +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +class CrazyGin { + public: + long double possibility(int numMoves){ + long long case_num = 0; + for(int m = 1; m <= numMoves ; m++){ + case_num += killAt(m, numMoves); + } + long double pos = (long double)case_num; + for(int m = 1; m <= numMoves ; m++){ + pos = pos / 5; + } + return pos; + } + + long long killAt(int m, int numMoves){ + if (m%2 == 1){ + return 0; + } + return untilKillKing(m) * afterKillKing(numMoves - m); + } + + // 王をm手目にちょうど倒す場合の数 + long long untilKillKing(int m){ + vector moveX = {-1, 0, 1,-1, 1}; + vector moveY = {-1,-1,-1, 1, 1}; + long long board[9][9] = {0}; //board[x][y] + long long nextBoard[9][9] = {0}; //次の内容 + vector friendPosX = {4, 5, 7, 2, 5, 2, 3, 7, 0, 1, 6, 8, 3, 5, 0, 1, 2, 4,6, 7, 8}; //王と味方の位置 + vector friendPosY = {0, 4, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8,8, 8, 8}; //王と味方の位置 + board[4][4] = 1; //初期位置 + + long long numPattern = 0; + for(int i = 0; i < m ; i++){ + for(int x = 0; x < 9 ; x++){ + for(int y = 0; y < 9 ; y++){ + for(int j = 0; j < moveX.size(); j++){ + if(x + moveX[j] >= 0 && x + moveX[j] < 9 + && y + moveY[j] >= 0 && y + moveY[j] < 9){ + nextBoard[x + moveX[j]][y + moveY[j]] += board[x][y]; + } + } + } + } + numPattern = nextBoard[4][0]; + //nextBoardをboardにコピー。その際、味方等の位置は0に + for(int y = 0; y < 9 ; y++){ + for(int x = 0; x < 9 ; x++){ + board[x][y] = nextBoard[x][y]; + nextBoard[x][y] = 0; + } + } + for(int k = 0; k < friendPosX.size(); k++){ + board[friendPosX[k]][friendPosY[k]] = 0; + } + } + return numPattern; + } + + // 王を倒したあとremainingSteps動く場合の数 + long long afterKillKing(int remainingSteps){ + vector moveX = {-1, 0, 1,-1, 1}; + vector moveY = {-1,-1,-1, 1, 1}; + long long board[9][9] = {0}; //board[x][y] + long long nextBoard[9][9] = {0}; //次の内容 + vector friendPosX = {5, 7, 2, 5, 2, 3, 7, 0, 1, 6, 8, 3, 5, 0, 1, 2, 4,6, 7, 8}; //味方の位置 + vector friendPosY = {4, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8,8, 8, 8}; //味方の位置 + board[4][0] = 1; //初期位置 + long long numPattern = 0; + for(int i = 0; i < remainingSteps ; i++){ + for(int x = 0; x < 9 ; x++){ + for(int y = 0; y < 9 ; y++){ + for(int j = 0; j < moveX.size(); j++){ + if(x + moveX[j] >= 0 && x + moveX[j] < 9 + && y + moveY[j] >= 0 && y + moveY[j] < 9){ + nextBoard[x + moveX[j]][y + moveY[j]] += board[x][y]; + } + } + } + } + //nextBoardをboardにコピー。その際、味方等の位置は0に + for(int y = 0; y < 9 ; y++){ + for(int x = 0; x < 9 ; x++){ + board[x][y] = nextBoard[x][y]; + nextBoard[x][y] = 0; + } + } + for(int k = 0; k < friendPosX.size(); k++){ + board[friendPosX[k]][friendPosY[k]] = 0; + } + } + + for(int y = 0; y < 9 ; y++){ + for(int x = 0; x < 9 ; x++){ + numPattern += board[x][y]; + } + } + return numPattern; + } +}; + +int main(){ + CrazyGin cg; + int numMoves = 20; + cout << cg.possibility(numMoves); +} diff --git a/a.out b/a.out new file mode 100755 index 0000000..37ca55e Binary files /dev/null and b/a.out differ diff --git a/autoexec.sh b/autoexec.sh new file mode 100755 index 0000000..e51d61e --- /dev/null +++ b/autoexec.sh @@ -0,0 +1,22 @@ +#!/bin/sh +if [ $# -ne 2 ]; then + echo "実行するには2個の引数が必要です。 + 第一引数: 監視対象ファイル名 + 第二引数: 監視対象ファイルが更新された際に実行されるコマンド + 例: 'gcc44 -lstdc++ -std=gnu++0x a.cpp && ./a.out'" + exit 1 +fi +echo "監視対象 $1" +echo "実行コマンド $2" +INTERVAL=1 #監視間隔, 秒で指定 +last=`ls --full-time $1 | awk '{print $6"-"$7}'` +while true; do + sleep $INTERVAL + current=`ls --full-time $1 | awk '{print $6"-"$7}'` + if [ $last != $current ] ; then + echo "" + echo "updated: $current" + last=$current + eval $2 + fi +done