题意:给定n*m个座椅,然后有b个是坏的,要做人,并且两个人不能相邻,问你最多坐多少人,最少坐多少人。
析:这个题其实并不难,只要当时一时没想清楚,结果就一直WA,就是最少的情况时,其实一个人可以占三个座位,而不是两个,就是这一点没想清楚,其他的就简单了。
代码如下:
#include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set> #include <queue> #include <algorithm> #include <vector> #include <map> #include <cctype> using namespace std; typedef long long LL; typedef pair<int, int> P; const int INF = 0x3f3f3f3f; const double inf = 0x3f3f3f3f3f3f3f; const double eps = 1e-8; const int maxn = 1e6 + 5; const int dr[] = {0, 0, -1, 1}; const int dc[] = {-1, 1, 0, 0}; int n, m, q; vector<int> a[1010]; int main(){ int T, ca = 0; scanf("%d", &T); while(T--){ scanf("%d %d %d", &n, &m, &q); for(int i = 0; i <= n; ++i) a[i].clear(); int tmp1, tmp2; while(q--){ scanf("%d %d", &tmp1, &tmp2); a[tmp1 + 1].push_back(tmp2 + 1); } for(int i = 1; i <= n; ++i) sort(a[i].begin(), a[i].end()); int ans1 = 0, ans2 = 0; for(int line = 1; line <= n; ++line){ if(a[line].empty()){ ans1 += (m+1) / 2; ans2 += (m+2) / 3; continue; } int head = 0, len = a[line].size(); for(int i = 0; i < len; ++i){ int lur = a[line][i]; int cha = lur - head - 1; ans1 += (cha+1) / 2; ans2 += (cha+2) / 3; head = lur; } int lur = m + 1; int cha = lur - head - 1; ans1 += (cha+1) / 2; ans2 += (cha+2) / 3; } printf("Case #%d: %d %d\n", ++ca, ans1, ans2); } return 0; }
时间: 2024-10-09 13:31:26