Association for Cool Machineries (Part 1) - ACM-ICPC Asia Regional Singapore 2015

#include<iostream>
#include<string>
#include<set>
#include<map>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>

using namespace std;

const int N = 211;

struct State
{
	int i;
	int j;
	int cmdpos;

	State(int ti, int tj, int tcmdpos) : i(ti), j(tj), cmdpos(tcmdpos)
	{

	}

	bool operator<(const State &t)const
	{
		if (i != t.i)
		{
			return i < t.i;
		}
		else if (j != t.j)
		{
			return j < t.j;
		}
		else if (cmdpos != t.cmdpos)
		{
			return cmdpos < t.cmdpos;
		}
		else
		{
			return false;
		}
	}

	bool operator==(const State &t)const
	{
		return !((*this) < t) && !(t < (*this));
	}

};

string createNextNCmd(string current, string cmd, int n)
{
	string ret = current;
	while ((int)ret.length() < n)
	{
		ret += cmd;
	}
	return ret.substr(0, n);
}

int main()
{
	int n;
	cin >> n;

	string cmd;
	cin >> cmd;

	int ri, rj;
	char M[N][N];

	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			cin >> M[i][j];
			if (M[i][j] == 'R')
			{
				ri = i;
				rj = j;
			}
		}
	}

	int res = -1;
	set<State> trail_length;
	bool found = false;
	string newCmd = "";
	State loopStartState(-1,-1,-1);
	State current(ri, rj, 0);

	while (true)
	{
		bool skipped = false;

		if (found)
		{
			if (current == loopStartState)
			{
				if (newCmd.length() == 0)
				{
					res = 1;
					break;
				}

				res = newCmd.length();
				
				for (int i = 2; i <= n; ++i)
				{
					if (newCmd.length() % i == 0)
					{
						int cmplen = newCmd.length() / i;
						int matched = 0;
						for (int j = 0; j < (int)newCmd.length(); j += cmplen)
						{
							if (strncmp(newCmd.c_str(), newCmd.c_str() + j, cmplen) == 0)
							{
								++matched;
							}
						}
						if (matched == i)
						{
							res = cmplen;
						}
					}
				}
				break;
			}
		}
		else
		{
			if (trail_length.find(current) != trail_length.end())
			{
				loopStartState = current;
				found = true;
			}
			else
			{
				trail_length.insert(current);
			}
		}

		switch (cmd[current.cmdpos])
		{
		case '<':
			current.j--;
			if (M[current.i][current.j] == '#')
			{
				current.j++;
				skipped = true;
			}
			break;
		case '>':
			current.j++;
			if (M[current.i][current.j] == '#')
			{
				current.j--;
				skipped = true;
			}
			break;
		case 'v':
			current.i++;
			if (M[current.i][current.j] == '#')
			{
				current.i--;
				skipped = true;
			}
			break;
		case '^':
			current.i--;
			if (M[current.i][current.j] == '#')
			{
				current.i++;
				skipped = true;
			}
			break;
		}

		if (!skipped && found)
		{
			newCmd += cmd[current.cmdpos];
		}

		++current.cmdpos;
		current.cmdpos %= cmd.length();
	}

	if (res == 0)
	{
		res = 1;
	}
	cout << res << endl;

	return 0;
}

ディレクトリ内ファイル列挙実行

カレントディレクトリで各ファイルに実行したいコマンドをtodoという名前だとする。

bash

#!/bin/bash

for f in ./*
do
	todo ${f} ${f%.*}.out
done

BAT

for %F in (.\*) do todo %f %~nf.out

バッチファイルとして実行する場合%Fを%%Fと書かなければならない。

参考:http://windows.g.hatena.ne.jp/cx20/20100203/p1

Microsoft Visual Studio Express 2012 for Windows Desktop のインストール画面で止まる

概要

http://www.microsoft.com/visualstudio/jpn/products/visual-studio-express-for-windows-desktop
から wdexpress_full.exe をダウンロードした後これを起動するとVisual Studioのロゴが出たのち、
何らかのプログラムが高頻度で起動・終了を繰り返し、ビジー状態が継続する。
また、Microsoft Visual Studio Express 2012 for Windows Desktop自体の起動後もこの症状になる。

判明した原因

解決策

予めwisptis.exeを起動する。このプログラムは普通(ドライブ名):\Windows\system32に存在する。

AOJ 0563 Walking Santa

問題概要

格子点上にn個の家(x_i,y_i)があり、サンタが(x,y)におりる。
各家までのマンハッタン距離の2倍の和を最小化せよ。
ただし、ひとつの家とサンタの位置とのマンハッタン距離だけ2倍しない。

続きを読む