夢追い人

"It takes a dreamer to make a dream come true."―Vincent Willem van Gogh

一歩後退・・・

この記事に詰め込みます、あしからず。
結果、
896->861
ド━(゚Д゚)━ ン !!!
100単位で下がってる人いて悲しんじゃいけないんだろうけどあと数センチのところで後退とは・・・

いとつらき緑・・・

PKU 3183

#include <cstdio>
#include <set>
using namespace std;
int main() {
	int N; scanf("%d",&N);
	int H[N];
	for (int i=0; i<N; i++) scanf("%d",&H[i]);
	set<int> ans;
	if (N==1) {
		printf("1\n");
		return 0;
	}
	if (H[0]>=H[1]) ans.insert(1);
	if (H[N-1]>=H[N-2]) ans.insert(N);
	for (int i=1; i<N-1; i++) {
		if (H[i-1]<=H[i]&&H[i]>=H[i+1]) ans.insert(i+1);
	}
	for (set<int>::iterator it=ans.begin(); it!=ans.end(); it++) {
		printf("%d\n", (*it));
	}
}

PKU 3191

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
string solve(int n, string res) {
	if (n==0) return "0";
	if (n==1) return "1"+res;
	if (n%2==0) {
		res = solve(n/-2, "0"+res);
	} else {
		res = solve((n-1)/-2, "1"+res);
	}
	return res;
}
int main() {
	int n;
	scanf("%d",&n);
	cout << solve(n, "") << endl;
}

SRM424 MagicSpell

やるだけ

class MagicSpell {
public:
   string fixTheSpell( string spell ) {
	string str = "";
	for (int i=0; i<spell.length(); i++) if (spell[i]=='A'||spell[i]=='Z')
		str += spell[i];
	reverse(str.begin(), str.end());
	int npos = 0;
	for (int i=0; i<spell.length(); i++) if (spell[i]=='A'||spell[i]=='Z')
		spell[i] = str[npos++];
	return spell;
   }
};

SRM424 ProductOfDigits

やるだけ

class ProductOfDigits {
public:
   int smallestNumber( int N ) {
	int res = 0;
	int digits[] = {9,8,7,6,5,4,3,2};
	if (N < 10) return 1;
	for (int i=0; i<8; i++) {
		while (N % digits[i] == 0) {
			N /= digits[i];
			res++;
		}
	}
	if (N > 10) return -1;
	else return res;
   }
};

そーだよ。この過去問が少し易し過ぎた。うん(゚д゚)(。_。)

SRM525 RainyRoad

マップをみたらDFS!
悪い癖だ・・・
そもそもこの問題で有効なのはBFSだったし・・・

それじゃなくても解けたし・・・
無駄な努力、時間ロス、萎え・・・

class RainyRoad {
public:
	bool dfs(vector<string> road, int x, int y, int N) {
		if (x==0&&y==N-1) return true;
		int dx[] = {-1,-1,0,1,1};
		int dy[] = {0,1,1,0,1};
		road[x][y]='-';
		for (int i=0; i<5; i++) {
			int nx=x+dx[i], ny=y+dy[i];
			if (nx>=0&&nx<2&&ny>=0&&ny<N&&road[nx][ny]=='.') {
				if (dfs(road, nx, ny, N)) return true;
			}
		}
		return false;
	}
   string isReachable( vector <string> road ) {
	int N = road[0].length();
	int y = 0;
	for (int i=0; i<N; i++) {
		if (road[0][i]=='.'&&road[1][i]=='.') {
			y++;
			if (y==N) return "YES";
		} else {
			if (road[0][y]=='W') y--;
			break;
		}
	}
	if (dfs(road, 0, y, N)) return "YES";
	else return "NO";
   }
};

これが三行で書けることに気づいた時の悲しさ・・・

SRM525 DropCoins

セグフォと戦ってた。
でも正解コード見ても俺にかける気がしなかった・・・

間違い晒し

class DropCoins {
public:
	int dfs(vector<vi> maps, int jo, int ka, int le, int ri, int bs, int sum, int K, int res, char flag) {
		if (sum==K) return res;
		if (sum<K) return -1;
		int temp = INT_MAX, sub=0;
		if (flag=='a') {
			jo++; ka++;
			if (jo>=bs) return res;
			if (jo>=0) {
				for (int i=0; i<bs; i++) {
					if (maps[jo][i]) {
						maps[jo][i]=0;
						sub++;
					}
				}
			}
		} else if (flag=='b') {	
			jo--; ka--;
			if (ka<0) return res;
			if (ka<bs) {
				for (int i=0; i<bs; i++) {
					if (maps[ka][i]) {
						maps[ka][i]=0;
						sub++;
					}
				}
			}
		} else if (flag=='c') {
			le++; ri++;
			if (le>=bs) return res;
			if (le>=0) {
				for (int i=0; i<bs; i++) {
					if (maps[i][le]) {
						maps[i][le]=0;
						sub++;
					}
				}
			}
		} else if (flag=='d') {
			le--; ri--;
			if (ri<0) return res;
			if (ri<bs) {
				for (int i=0; i<bs; i++) {
					if (maps[i][ri]) {
						maps[i][ri]=0;
						sub++;
					}
				}
			}
		}
		char flags[] = {'a','b','c','d'};
		for (int i=0; i<4; i++) {
			int tres = dfs(maps,jo,ka,le,ri,bs,sum-sub,K,res+1,flags[i]);
			if (tres!=-1) res=min(res,tres);
		}
		if (temp==INT_MAX) return -1;
		else return temp;
	}
	
	int getMinimum( vector <string> board, int K ) {
		int bs = board.size(), sum = 0;
		vector<vi> maps(bs, vi(bs));
		for (int i=0; i<bs; i++) for (int j=0; j<bs; j++) {
			if (board[i][j]=='.') maps[i][j]=0;
			else maps[i][j]=1;
			sum += maps[i][j];
		}
		int jo=-1,ka=bs,le=-1,ri=bs;
		char flags[] = {'a','b','c','d'};
		int res = INT_MAX;
		for (int i=0; i<4; i++) {
			int tres = dfs(maps,jo,ka,le,ri,bs,sum,K,0,flags[i]);
			if (tres!=-1) res=min(res,tres);
		}
		if (res==INT_MAX) return -1;
		else return res;
	}
};