码迷,mamicode.com
首页 > 其他好文 > 详细

UVALive 7512 November 11th 题解

时间:2019-01-26 23:47:32      阅读:284      评论:0      收藏:0      [点我收藏+]

标签:cas   --   \n   memset   for   color   sort   style   mes   

思路:心态大崩,最多不讲了,最少应该是三个一组,比如......应该是.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
*/

 

UVALive 7512 November 11th 题解

标签:cas   --   \n   memset   for   color   sort   style   mes   

原文地址:https://www.cnblogs.com/KirinSB/p/10325201.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!