本文共 1332 字,大约阅读时间需要 4 分钟。
思路:心态大崩,最多不讲了,最少应该是三个一组,比如......应该是.S..S.,这样占的最多
代码:
#include #include #include #include #include #include #include #include #include typedef long long ll;using namespace std;const int maxn = 1000 + 10;const int MOD = 1e9 + 7;const int INF = 0x3f3f3f3f;int row[maxn][maxn], cnt[maxn];int getMax(int s){ return (s + 1) / 2;}int getMin(int s){ if(s % 3 == 0){ return s / 3; } else if(s % 3 == 1){ return (s + 2) / 3; } else return (s + 1) / 3;}int main(){ int t, ca = 1; scanf("%d", &t); while(t--){ int b, r, s; scanf("%d%d", &r, &s); scanf("%d", &b); memset(cnt, 0 ,sizeof(cnt)); for(int i = 1; i <= b; i++){ int x, y; scanf("%d%d", &x, &y); row[x][cnt[x]++] = y; } int Max = 0, Min = 0; for(int i = 0; i < r; i++){ if(cnt[i] == 0){ Max += getMax(s); Min += getMin(s); } else{ sort(row[i], row[i] + cnt[i]); for(int j = 0; j < cnt[i]; j++){ if(j == 0){ int tmp = row[i][j] - 0; Max += getMax(tmp); Min += getMin(tmp); } else{ int tmp = row[i][j] - row[i][j - 1] - 1; Max += getMax(tmp); Min += getMin(tmp); } } int tmp = s - 1 - row[i][cnt[i] - 1]; Max += getMax(tmp); Min += getMin(tmp); } } printf("Case #%d: %d %d\n", ca++, Max, Min); } return 0;}/*32 310 12 301 110 0*/
转载于:https://www.cnblogs.com/KirinSB/p/10325201.html