SRM588 div2

昨天晚上做的, 一開始跟宿舍哥們說了兩句話, 導致第一題出的慢了, 後來出了500pt, 之後一直再做1000pt, 打完後有個bug一直沒調出來所以就遺憾的兩題了。。。 今早把1000pt交上發現是對的。。。一句話 還是太弱了!!!!


250pt: 不解釋

500pt:由於歌曲最多隻有15種, 所以可以枚舉2 ^ 15種情況, 如果確定了是那幾首歌曲那麼所用的總時間就是歌曲時間的和再加上換音調的時間不難發現換調的最優決策就從小到大或者從大到小。。。。


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class GUMIAndSongsDiv2 {
public:
	int maxSongs(vector <int>, vector <int>, int);
};

int GUMIAndSongsDiv2::maxSongs(vector <int> d, vector <int> t, int T) {
	int n = d.size();
	int res = 0;
	for (int i = (1 << n) - 1; i >= 0; i--) {
		int s = i;
		int omax = -1, omin = 1000000000;
		int c = 0;
		int sum = 0;
		for (int j = 0; j < n; j++) {
			if ((1 << j) & s) {
				omax = max(omax, t[j]), omin = min(omin, t[j]);
				c++;
				sum += d[j];
			}
		}

		if (c <= res) continue;
		else {
			if (sum + omax - omin <= T) res = c;
		}
	}	
	return res;
}

<%:testing-code%>
//Powered by [KawigiEdit] 2.0!

1000pt:

這題我的做法就是暴力求出每一輪Bob可能在的位置保存在一個set裏面(自動去重)然後如果到某一輪set爲空了那麼就是Alice wins否則就是Bob wins。。。

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class GameInDarknessDiv2 {
public:
	string check(vector <string>, vector <string>);
};

typedef pair<int, int> P;
#define mp make_pair
#define se second
#define fi first

set<P> S;

int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};

vector<P> vec;

string GameInDarknessDiv2::check(vector<string> map, vector <string> move) {
	S.clear();
	int r = map.size(), m = move.size(), c = map[0].size();
	int ax = 0, ay = 0, bx = 0, by = 0;

	for (int i = 0; i < r; i++)
		for (int j = 0; j < c; j++)
			if (map[i][j] == 'A') ax = i, ay = j;
			else if (map[i][j] == 'B') bx = i, by = j;

	S.insert(mp(bx, by));
	
	string mov = "";
	for (int i = 0; i < m; i++) {
		mov += move[i];
	}

	m = mov.size();

	for (int i = 0; i < m; i++) {
		map[ax][ay] = '.';
		if (mov[i] == 'U') ax--;
		else if (mov[i] == 'D') ax++;
		else if (mov[i] == 'L') ay--;
		else ay++;
		map[ax][ay] = 'A';
		S.erase(mp(ax, ay));

		if (S.size() == 0) return "Alice wins";
		

		vec.clear();
		for (set<P>::iterator j = S.begin(); j != S.end(); j++) {
			vec.push_back(*j);
		}

		S.clear();

		for (int i = 0; i < vec.size(); i++) {
			P t = vec[i];
			for (int k = 0; k < 4; k++) {
				int tx = t.fi + dx[k], ty = t.se + dy[k];
				if (tx >= 0 && tx < r && ty >= 0 && ty < c && map[tx][ty] != '#'
						&& map[tx][ty] != 'A') {
					S.insert(mp(tx, ty));
				} 
			}
		}

	}

	if (!S.size()) return "Alice wins";
	return "Bob wins";
}


//Powered by [KawigiEdit] 2.0!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章