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!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值