UVALive 7512 November 11th 题解

思路:心态大崩,最多不讲了,最少应该是三个一组,比如......应该是.S..S.,这样占的最多

代码:

#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<cstdio>
#include<cstring>
#include<sstream>
#include<algorithm>
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;
}
/*
3
2 3
1
0 1
2 3
0
1 1
1
0 0
*/

 

posted @ 2019-01-26 22:48  KirinSB  阅读(113)  评论(0编辑  收藏  举报