UVALive 7512 November 11th(脑洞)

题目链接:点击打开链接

给出坏凳子的位置, 座位不能挨着坐, 问最多可以做多少人, 以及最少可以坐多少人使得不能再有可以坐的位置.

最多可以坐多少人, 只要中间空一个即可, 本题wa点在最少坐的人数, 中间空两个也可以... 比如.S..S.所以空的位置大于2时, 分母为3.

AC代码:

#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
#include "queue"
#include "stack"
#include "cmath"
#include "utility"
#include "map"
#include "set"
#include "vector"
#include "list"
#include "string"
#include "cstdlib"
using namespace std;
typedef long long ll;
#define X first
#define Y second
#define exp 1e-8
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXN = 1005;
int t, r, s, b;
std::vector v[MAXN];
int main(int argc, char const *argv[])
{
	scanf("%d", &t);
	for(int cas = 1; cas <= t; ++cas) {
		for(int i = 0; i < MAXN; ++i)
			v[i].clear();
		int ans1 = 0, ans2 = 0;
		scanf("%d%d", &r, &s);
		scanf("%d", &b);
		while(b--) {
			int x, y;
			scanf("%d%d", &x, &y);
			v[x].push_back(y);
		}
		for(int i = 0; i < r; ++i) {
			sort(v[i].begin(), v[i].end());
			v[i].push_back(s);
		}
		for(int i = 0; i < r; ++i) {
			int x = -1;
			for(int j = 0; j < v[i].size(); ++j) {
				int len = v[i][j] - x - 1;
				x = v[i][j];
				if(len <= 0) continue;
				if(len <= 2) {
					ans1++;
					ans2++;
				}
				else {
					ans1 += (len + 1) / 2;
					ans2 += (len + 2) / 3;
				}
			}
		}
		printf("Case #%d: %d %d\n", cas, ans1, ans2);
	}
	return 0;
}


你可能感兴趣的:(UVA,脑洞题目,STL)